From b4f2c55c76abb7c0c41729af5fd6466df1dbfda2 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Tue, 5 Jun 2018 18:49:02 +0300 Subject: [PATCH 1/2] Fix sock_read timeout --- aiohttp/client_proto.py | 7 +++++-- docs/client_quickstart.rst | 13 +++++++++++-- tests/test_client_functional.py | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/aiohttp/client_proto.py b/aiohttp/client_proto.py index 91fa45a2d3a..b42a769c704 100644 --- a/aiohttp/client_proto.py +++ b/aiohttp/client_proto.py @@ -51,6 +51,7 @@ def close(self): transport.close() self.transport = None self._payload = None + self._drop_timeout() return transport def is_connected(self): @@ -162,8 +163,10 @@ def _reschedule_timeout(self): self._read_timeout_handle = None def _on_read_timeout(self): - self.set_exception( - ServerTimeoutError("Timeout on reading data from socket")) + exc = ServerTimeoutError("Timeout on reading data from socket") + self.set_exception(exc) + if self._payload is not None: + self._payload.set_exception(exc) def data_received(self, data): if not data: diff --git a/docs/client_quickstart.rst b/docs/client_quickstart.rst index 206104c1d9f..a22c8b01166 100644 --- a/docs/client_quickstart.rst +++ b/docs/client_quickstart.rst @@ -415,7 +415,15 @@ Supported :class:`ClientTimeout` fields are: ``connect`` - The maximum time for connection establishment. + Total timeout for acquiring a connection from pool. The time + consists connection establishment for a new connection or + waiting for a free connection from a pool if pool connection + limits are exceeded. + + ``sock_connect`` + + A timeout for connecting to a peer for a new connection, not + given from a pool. ``sock_read`` @@ -426,4 +434,5 @@ All fields a floats, ``None`` or ``0`` disables a particular timeout check. Thus the default timeout is:: - aiohttp.ClientTimeout(total=5*60, connect=None, sock_read=None) + aiohttp.ClientTimeout(total=5*60, connect=None, + sock_connect=None, sock_read=None) diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py index 620741511b8..ca6d00a62b6 100644 --- a/tests/test_client_functional.py +++ b/tests/test_client_functional.py @@ -2613,3 +2613,22 @@ async def handler(request): with pytest.raises(aiohttp.ServerTimeoutError): await client.get('/') + + +async def test_read_timeout_on_prepared_response(aiohttp_client): + async def handler(request): + resp = aiohttp.web.StreamResponse() + await resp.prepare(request) + await asyncio.sleep(5) + await resp.drain() + return resp + + app = web.Application() + app.add_routes([web.get('/', handler)]) + + timeout = aiohttp.ClientTimeout(sock_read=0.1) + client = await aiohttp_client(app, timeout=timeout) + + with pytest.raises(aiohttp.ServerTimeoutError): + async with await client.get('/') as resp: + await resp.read() From 038ef9399e7ea8543c192cf2724cabdb473cef84 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Tue, 5 Jun 2018 18:50:28 +0300 Subject: [PATCH 2/2] Add changelog --- CHANGES/3053.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/3053.bugfix diff --git a/CHANGES/3053.bugfix b/CHANGES/3053.bugfix new file mode 100644 index 00000000000..261a7d29281 --- /dev/null +++ b/CHANGES/3053.bugfix @@ -0,0 +1 @@ +Fix ``sock_read`` timeout. \ No newline at end of file