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.
05d1fe2 to
142b5ec
Compare
savannahostrowski
left a comment
There was a problem hiding this comment.
Ah, good catch! I’m happy to merge this once #502 is in and CI is green. That should fix the unrelated Tornado/PyPy test failure!
Thank you!
Thanks for the review, Savannah! #502 has landed and Hugo already merged The new workflow runs are currently sitting in Happy to adjust anything if you'd prefer a different commit shape before merging. |
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.