aiohttp
aiohttp copied to clipboard
Client raises asyncio.TimeoutError
Describe the bug
Client raises asyncio.TimeoutError
, although according to the documentation it seems that aiohttp.ServerTimeoutError
should be raised.
To Reproduce
- Run
nc -l 8000
- Run:
import aiohttp
import asyncio
async def main():
timeout = aiohttp.ClientTimeout(total=10)
async with aiohttp.ClientSession(timeout=timeout) as session:
try:
async with session.get('http://127.0.0.1:8000'):
pass
except aiohttp.ServerTimeoutError:
print('aiohttp.ServerTimeoutError')
except aiohttp.ClientError:
print('aiohttp.ClientError')
except asyncio.TimeoutError:
print('asyncio.TimeoutError')
if __name__ == '__main__':
asyncio.run(main())
- Wait 10 seconds
- Get result: "asyncio.TimeoutError"
Expected behavior
Result: "aiohttp.ServerTimeoutError"
Logs/tracebacks
asyncio.TimeoutError
Python Version
3.11.0
aiohttp Version
3.8.3
multidict Version
6.0.2
yarl Version
1.8.1
OS
macOS 12.6.1
Related component
Client
Additional context
No response
Code of Conduct
- [X] I agree to follow the aio-libs Code of Conduct
Hey @graingert, can this be related to your patch #6877?
Looks like the code does raise ServerTimeoutError
on (1) connection timeout
(https://github.com/aio-libs/aiohttp/blob/0d39c84ad47115b7b0af411fa3a6080c56f3cdff/aiohttp/client_proto.py#L197) and on read timeout (https://github.com/aio-libs/aiohttp/blob/0d39c84ad47115b7b0af411fa3a6080c56f3cdff/aiohttp/client.py#L504)
This is not a new behavior. At least since version 2.3.10, this case raises asyncio.TimeoutError
exception.
Thanks for posting this question @poofeg. I had thought we had handled timeouts in our retry logic, but we didn't identify this exception as one that needs to be handled as well.
I would suggest:
- Update the documentation to clarify that
asyncio.TimeoutError
may be raised in the event of a timed-out request. - Consider (but probably avoid) raising
ServerTimeoutError
instead ofasyncio.TimeoutError
in this case.
Do people agree the documentation should be updated to call out this behavior?