File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Fixed response reading from closed session to throw an error immediately instead of timing out -- by :user: `Dreamsorcerer `.
Original file line number Diff line number Diff line change @@ -296,6 +296,9 @@ def end_http_chunk_receiving(self) -> None:
296296 set_result (waiter , None )
297297
298298 async def _wait (self , func_name : str ) -> None :
299+ if not self ._protocol .connected :
300+ raise RuntimeError ("Connection closed." )
301+
299302 # StreamReader uses a future to link the protocol feed_data() method
300303 # to a read coroutine. Running two read coroutines at the same time
301304 # would have an unexpected behaviour. It would not possible to know
Original file line number Diff line number Diff line change 2929 SocketTimeoutError ,
3030 TooManyRedirects ,
3131)
32- from aiohttp .pytest_plugin import AiohttpClient , TestClient
32+ from aiohttp .pytest_plugin import AiohttpClient , AiohttpServer , TestClient
3333from aiohttp .test_utils import unused_port
3434
3535
@@ -3645,3 +3645,20 @@ async def handler(_: web.Request) -> web.Response:
36453645 session = await aiohttp_client (app , raise_for_status = None ) # type: ignore[arg-type]
36463646
36473647 await session .get ("/" )
3648+
3649+
3650+ async def test_exception_when_read_outside_of_session (
3651+ aiohttp_server : AiohttpServer ,
3652+ ) -> None :
3653+ async def handler (request : web .Request ) -> web .Response :
3654+ return web .Response (body = b"1" * 1000000 )
3655+
3656+ app = web .Application ()
3657+ app .router .add_get ("/" , handler )
3658+
3659+ server = await aiohttp_server (app )
3660+ async with aiohttp .ClientSession () as sess :
3661+ resp = await sess .get (server .make_url ("/" ))
3662+
3663+ with pytest .raises (RuntimeError , match = "Connection closed" ):
3664+ await resp .read ()
You can’t perform that action at this time.
0 commit comments