← Back to Pull requests

Fix `bm_fastapi` failing when an HTTP proxy is configured #505

Closed
unknown closed this pull request without merging on Nov 09, 2026 17:53 UTC
View on GitHub
unknown unknown commented on Nov 05, 2026 15:11 UTC
Author

Fixes #504

Problem

The fastapi benchmark (bm_fastapi) fails when the environment has an HTTP
proxy configured — e.g. HTTP_PROXY/http_proxy set, which is common in CI or
corporate environments — and 127.0.0.1 is not listed in NO_PROXY.

The benchmark starts a uvicorn server on 127.0.0.1 and then talks to it with
httpx.AsyncClient(). Because httpx reads proxy configuration from the
environment by default, the request to http://127.0.0.1:<port>/items/0 is
routed through the proxy. The proxy cannot reach the benchmark machine's
loopback address, so it returns 503 Service Unavailable and the benchmark
dies:

httpx.HTTPStatusError: Server error '503 Service Unavailable' for url 'http://127.0.0.1:40027/items/0'
...
RuntimeError: Benchmark died
ERROR: Benchmark fastapi failed: Benchmark died

Fix

Create the client with trust_env=False so it never reads proxy (or .netrc)
settings from the environment:

async with httpx.AsyncClient(trust_env=False) as client:

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=False behaves identically to the default,
so benchmark results are unaffected for the common case.

Only bm_fastapi is 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.1 absent from NO_PROXY:

$ python -m pyperformance run bm_fastapi --inherit-environ http_proxy,https_proxy,no_proxy

  • Before the change: Benchmark fastapi failed: Benchmark died with the 503 above.

  • After the change: the benchmark completes and reports a result.
  • Diff: 237 lines (+177 / -60) across 2 files Reviewer: savannahostrowski Review duration: 5922m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.60) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.60 · 237 lines diff across 2 files
    0.60
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.327
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.060
    Real PR Conversation Timeline
    1 comments
    "Review active on #505"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 60.4% (MEDIUM) · Higher = larger blast radius
    60.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23.8% · Safe to merge
    23.8%