Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sock read timeout #3055

Merged
merged 2 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/3053.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``sock_read`` timeout.
7 changes: 5 additions & 2 deletions aiohttp/client_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def close(self):
transport.close()
self.transport = None
self._payload = None
self._drop_timeout()
return transport

def is_connected(self):
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 11 additions & 2 deletions docs/client_quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``

Expand All @@ -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)
19 changes: 19 additions & 0 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()