diff --git a/starlette/requests.py b/starlette/requests.py index b27e8e1e2..4c106376f 100644 --- a/starlette/requests.py +++ b/starlette/requests.py @@ -1,5 +1,6 @@ from __future__ import annotations +import asyncio import json import typing from http import cookies as http_cookies @@ -295,13 +296,14 @@ async def close(self) -> None: async def is_disconnected(self) -> bool: if not self._is_disconnected: - message: Message = {} - - # If message isn't immediately available, move on - with anyio.CancelScope() as cs: - cs.cancel() - message = await self._receive() - + try: + message = await asyncio.wait_for( + self._receive(), timeout=0.0000001 + ) + except asyncio.TimeoutError: + message = {} + + print("STARLETTE MESSAGE", message, flush=True) if message.get("type") == "http.disconnect": self._is_disconnected = True