Repository navigation
Conversation
httpx.AsyncClient() reads HTTP_PROXY/HTTPS_PROXY/NO_PROXY from the
environment by default. When a proxy is set, the benchmark routes
requests to its local 127.0.0.1 server through that proxy, which cannot
reach the loopback server and returns 503 Service Unavailable, causing
the benchmark to fail ("Benchmark died").
Pass trust_env=False since the benchmark only ever talks to localhost.
sendaoYan
force-pushed
the
fix-fastapi-proxy
branch
from
November 5, 2026 15:13
05d1fe2 to
142b5ec
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #504
Problem
The
fastapibenchmark (bm_fastapi) fails when the environment has an HTTPproxy configured — e.g.
HTTP_PROXY/http_proxyset, which is common in CI orcorporate environments — and
127.0.0.1is not listed inNO_PROXY.The benchmark starts a uvicorn server on
127.0.0.1and then talks to it withhttpx.AsyncClient(). Because httpx reads proxy configuration from theenvironment by default, the request to
http://127.0.0.1:<port>/items/0isrouted through the proxy. The proxy cannot reach the benchmark machine's
loopback address, so it returns
503 Service Unavailableand the benchmarkdies:
Fix
Create the client with
trust_env=Falseso it never reads proxy (or.netrc)settings from the environment:
This is correct for this benchmark because it only ever connects to its own
loopback server, so it must never be routed through a proxy. In environments
with no proxy configured,
trust_env=Falsebehaves identically to the default,so benchmark results are unaffected for the common case.
Only
bm_fastapiis affected: the other networking benchmarks(
bm_tornado_http,bm_asyncio_tcp,bm_asyncio_websockets,bm_async_tree)use clients that do not read proxy environment variables.
Testing
Reproduced by running the benchmark with proxy environment variables inherited
and
127.0.0.1absent fromNO_PROXY:$ python -m pyperformance run bm_fastapi --inherit-environ http_proxy,https_proxy,no_proxyBenchmark fastapi failed: Benchmark diedwith the 503 above.