Sync client ignores timeout for unreachable site (but async client works as expected) #3583
Replies: 1 comment
|
It may help to separate connection establishment from the later phases of the request. HTTPX exposes different timeout exceptions for connect, read, write, and pool acquisition, so the exception type and the point at which it occurs can narrow the cause. For synchronous code, compare the request using a long-lived httpx.Client; for async code, use one long-lived httpx.AsyncClient rather than creating a client inside every call. Also check whether the timeout occurs only through a proxy, on a particular address family, or during DNS resolution. As a controlled comparison, retry with trust_env=False to exclude proxy environment variables from HTTPX's default configuration. A controlled request to a known endpoint can distinguish a local networking or proxy problem from an HTTPX-specific problem. If the failure is specifically ConnectTimeout, please include the transport, proxy configuration, HTTPX version, Python version, operating system, exception type, and a minimal reproducible example. Application-level logging of the exception type, host, proxy configuration, and elapsed time is useful; resolved-address details, where available, are not standard HTTPX output. I would avoid treating this as an HTTPX bug until the same minimal example reproduces outside the application environment. References: |
Uh oh!
There was an error while loading. Please reload this page.
Hi! I'm encountering an issue where the
timeoutargument seems to behave inconsistently between the synchronous and asynchronous clients.I'm trying to query a site that delays responses based on geolocation or VPN - if you're from the "wrong" country, it just hangs (likely silently blocks the connection). I'm setting a timeout of 3 seconds to avoid this, but only the async client behaves as expected.
Code to reproduce
Output:
Expected:
All three should timeout after ~3 seconds.
Actual:
Only the async client respects the timeout. Both sync and top-level httpx.get(...) calls hang for ~18 seconds.
Environment
httpx 0.28.1
python 3.13.0
Is this a bug or am I misunderstanding how
timeoutshould work for sync requests? Would appreciate any insight - thanks in advance!All reactions