Describe the bug
Once the TCP connection to the server is successfully established and the client has sent its request it will start waiting for a response from the server using epoll_wait with a timeout value of -1 (indefinitely). If the server simply never send a response or the connectivity is lost between the client and the server for a prolonged period epoll_wait will simply never return. Using ClientTimeout.sock_read in addition to ClientTimeout.total solves the issue (makes epoll_wait be called with a timeout instead of -1) but the documentation gives the impression that ClientTimeout.total should be enough. Since the default is total=5*60 and sock_timeout=None, every HTTP request done using aiohttp is susceptible to hanging forever in rare cases unless sock_read is set specifically.
To Reproduce
Do a request while using strace on the process and look for the epoll_wait that is done right after the request headers have been sent. Example:
sendto(6, "GET /foo HTTP/1.1\r\nHost: 127"..., 133, 0, NULL, 0) = 133
epoll_wait(3, [{events=EPOLLIN, data={u32=6, u64=6}}], 2, -1) = 1
The last argument to epoll_wait is the timeout.
Expected behavior
The client should under no circumstances hang forever when a total timeout value has been set (as is the default).
Logs/tracebacks
Python Version
$ python --version
Python 3.11.2
aiohttp Version
$ python -m pip show aiohttp
Name: aiohttp
Version: 3.12.12
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author:
Author-email:
License: Apache-2.0
Location: /x/y/.local/python-venv/lib/python3.11/site-packages
Requires: aiohappyeyeballs, aiosignal, attrs, frozenlist, multidict, propcache, yarl
Required-by: aiohttp_socks, jsonrpc-async
multidict Version
$ python -m pip show multidict
Name: multidict
Version: 6.0.4
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /x/y/.local/python-venv/lib/python3.11/site-packages
Requires:
Required-by: aiohttp, yarl
propcache Version
$ python -m pip show propcache
Name: propcache
Version: 0.3.2
Summary: Accelerated property cache
Home-page: https://github.com/aio-libs/propcache
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: /x/y/.local/python-venv/lib/python3.11/site-packages
Requires:
Required-by: aiohttp, yarl
yarl Version
$ python -m pip show yarl
Name: yarl
Version: 1.20.1
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: /x/y/.local/python-venv/lib/python3.11/site-packages
Requires: idna, multidict, propcache
Required-by: aiohttp
OS
Linux
Related component
Client
Additional context
No response
Code of Conduct
Describe the bug
Once the TCP connection to the server is successfully established and the client has sent its request it will start waiting for a response from the server using
epoll_waitwith a timeout value of -1 (indefinitely). If the server simply never send a response or the connectivity is lost between the client and the server for a prolonged periodepoll_waitwill simply never return. UsingClientTimeout.sock_readin addition toClientTimeout.totalsolves the issue (makesepoll_waitbe called with a timeout instead of -1) but the documentation gives the impression thatClientTimeout.totalshould be enough. Since the default istotal=5*60andsock_timeout=None, every HTTP request done using aiohttp is susceptible to hanging forever in rare cases unlesssock_readis set specifically.To Reproduce
Do a request while using strace on the process and look for the
epoll_waitthat is done right after the request headers have been sent. Example:The last argument to epoll_wait is the timeout.
Expected behavior
The client should under no circumstances hang forever when a
totaltimeout value has been set (as is the default).Logs/tracebacks
Python Version
aiohttp Version
multidict Version
propcache Version
yarl Version
OS
Linux
Related component
Client
Additional context
No response
Code of Conduct