Timeouts are not applied during socks5 initialization.
I encountered a problem when using socks5 proxy. Sometimes the server would not get a response during socks5 initialization, causing the thread to hang when using httpx.Client. Based on this I checked the initialization of socks5 connection. And found that timeouts are not applied during socks5 initialization.
I've encountered exactly the same issue when using the socks5h proxy and httpx/httpcore/openai.
The request hung for 25 minutes before finally failing with:
Traceback (most recent call last): File ".../python3.12/site-packages/httpx/_transports/default.py", line 101, in map_httpcore_exceptions yield File ".../python3.12/site-packages/httpx/_transports/default.py", line 394, in handle_async_request resp = await self._pool.handle_async_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/httpcore/_async/connection_pool.py", line 256, in handle_async_request raise exc from None File ".../python3.12/site-packages/httpcore/_async/connection_pool.py", line 236, in handle_async_request response = await connection.handle_async_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/httpcore/_async/socks_proxy.py", line 295, in handle_async_request raise exc File ".../python3.12/site-packages/httpcore/_async/socks_proxy.py", line 231, in handle_async_request stream = await self._network_backend.connect_tcp(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/httpcore/_backends/auto.py", line 31, in connect_tcp return await self._backend.connect_tcp( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/httpcore/_backends/anyio.py", line 113, in connect_tcp with map_exceptions(exc_map): ^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/hansbrende/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 158, in exit self.gen.throw(value) File ".../python3.12/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectError: All connection attempts failed
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File ".../python3.12/site-packages/openai/_base_client.py", line 1529, in request response = await self._client.send( ^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/httpx/_client.py", line 1629, in send response = await self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/httpx/_client.py", line 1657, in _send_handling_auth response = await self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/httpx/_client.py", line 1694, in _send_handling_redirects response = await self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/httpx/_client.py", line 1730, in _send_single_request response = await transport.handle_async_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../python3.12/site-packages/httpx/_transports/default.py", line 393, in handle_async_request with map_httpcore_exceptions(): ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/hansbrende/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py", line 158, in exit self.gen.throw(value) File ".../python3.12/site-packages/httpx/_transports/default.py", line 118, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectError: All connection attempts failed
@tomchristie @graingert I noticed a linked PR has been open for 2 months...
UPDATE: actually seems to be working fine on my end--the extended time period before failure was actually due to 2 successive retries that openai puts into their default parameters (I think). False alarm, sorry.