-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
ClientTimeout values of 0 don't disable timeouts #5527
Comments
The change you reference doesn't appear to ever have been backported, so that change is not in aiohttp <4. |
I was trying different versions to narrow the issue down and saw it in the list of commits here v3.6.3...v3.7.0b0 and in the changelog . The behavior of the timeouts definitely changed between 3.6.3 and 3.7.0b0. When I removed the check here 3.7.x versions behaved the same as 3.6.3 in my test case. |
Ah nevermind, I see now. The commit you mentioned is: 5996f85 But, the PR you linked to was for master, so shows different code. That was confusing me. |
But, that check only stops it from calling There must be some other cause... |
Or, maybe 3.6 only works by luck as well... |
I considered that and tried testing this earlier today. With the server below which waits 5 seconds before returning a request 3.6 works and 3.7 fails. My logic here is that if the rounding really meant that my 0s timeouts were actually something between 0 and 1 second instead of being disabled then a request which took 5 seconds should timeout after ~1s. With 3.6.3 I don't see that happening.
from aiohttp import web
import asyncio
routes = web.RouteTableDef()
@routes.get("/")
async def get(request):
await asyncio.sleep(5)
return web.json_response({"key":"value"})
if __name__ == "__main__":
app = web.Application()
app.add_routes(routes)
web.run_app(app) and using this client: timeout = aiohttp.ClientTimeout(
total=0,
connect=0,
sock_connect=0,
sock_read=0
)
async with aiohttp.ClientSession(timeout=timeout) as session:
print(await session.get("http://localhost:8080")) With 3.6.3 ryan@debian:~$ time python test.py
<ClientResponse(http://localhost:8080) [200 OK]>
<CIMultiDictProxy('Content-Type': 'application/json; charset=utf-8', 'Content-Length': '16', 'Date': 'Tue, 09 Mar 2021 19:59:13 GMT', 'Server': 'Python/3.9 aiohttp/3.6.3')>
real 0m5.183s
user 0m0.160s
sys 0m0.021s and if I change any of the timeouts to a non-zero value it does what I expect. With ryan@debian:~$ time python test.py
Traceback (most recent call last):
...
aiohttp.client_exceptions.ServerTimeoutError: Timeout on reading data from socket
real 0m2.183s
user 0m0.162s
sys 0m0.020s |
Thanks, so if I try with that server, then I see it fails with the unmodified 3.7 code. However, if I change the line to add 0.1 seconds: Then it works fine. So, it seems like the timeout is not being respected, as long as it has opened the connection before the timeout, or something along those lines... |
OK, I think I've found the issue. The sock_connect will always do this timeout. So, it was working by luck as we initially thought in the old code. But, it is only opening the connection that is affected, which is why your test server doesn't reproduce it. |
Appears to already have been fixed on master anyway. Copying the change into 3.8. |
🐞 Describe the bug
ClientTimeout
values of 0 andNone
are treated differently. The docs here state:and versions 3.6.3 and earlier do work this way. After #5091 this behavior was changed.
💡 To Reproduce
This simple example illustrates the issue:
With v3.6.3:
With v3.7.4:
This timeout happens immediately.
With 3.7.4 if I change the timeout values from 0 to
None
it works correctly.💡 Expected behavior
Timeouts with values of 0 should be ignored (or the docs updated to say 0 doesn't disable the timeouts).
The text was updated successfully, but these errors were encountered: