-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Long story short
Setting a short timeout on session.get(...)
overrides the ClientSession
timeout and causes all requests to timeout within the session.get(...)
timeframe.
Expected behaviour
The session.get(...)
timeout should be per-request, while the timeout set in ClientSession
should be cumulative for the session. I should be able to set an infinite ClientSession
timeout with a limited session.get(...)
per request and have it go until all tasks are completed.
Actual behaviour
Once a short session.get(...)
timeout is set, it no longer respects the ClientSession
timeout. This makes long lists of sites impossible to go through because either the timeout gets hit and everything gets cancelled, or you choose not to use a timeout and all connectors get stuck waiting indefinitely on non responding sites.
Steps to reproduce
Create something such as:
timeout = aiohttp.ClientTimeout(total=600)
connector = aiohttp.TCPConnector(limit=40)
dummy_jar = aiohttp.DummyCookieJar()
async with aiohttp.ClientSession(connector=connector, timeout=timeout, cookie_jar=dummy_jar) as session:
for site in sites:
task = asyncio.ensure_future(make_request(session, site))
tasks.append(task)
await asyncio.wait(tasks)
Then for the make_request
you can have something such as:
async def make_request(session, site):
async with session.get(site, timeout=15) as response:
return await response.read()
Throw in a large list of different sites (some unreachable) for sites
, and notice after 15 seconds you will start to get a bunch of timeouts. It seems that's happening because the 15 seconds defined in session.get(...)
is an aggregate for all requests instead of the current request it's making.
The expected result in the above case is to allow 600 seconds for all requests in the session, but limit each request to only 15 seconds.
Your environment
Windows 7x64
Python 3.7.0
aiohttp 3.3.2