Jump to solution
Verify

The Fix

Upgrade to version 0.15.2 or later.

Based on closed encode/httpx issue #1310 · PR/commit linked

Jump to Verify Open PR/Commit
@@ -859,7 +859,7 @@ def _send_single_request(self, request: Request, timeout: Timeout) -> Response: def on_close(response: Response) -> None: - response.elapsed = datetime.timedelta(timer.sync_elapsed()) + response.elapsed = datetime.timedelta(seconds=timer.sync_elapsed()) if hasattr(stream, "close"):
repro.py
import httpx client = httpx.Client() with client.stream("GET", "https://httpbin.org/basic-auth/user/pass", auth=("user", "pass")) as r: print(r) print(r.elapsed)
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\nUpgrade to version 0.15.2 or later.\nWhen NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.\n\n

Why This Fix Works in Production

  • Trigger: The elapsed time reported was incoherent, leading to confusion in performance metrics.
  • Mechanism: The elapsed time was incorrectly calculated without converting to seconds
  • Why the fix works: Fixes the incorrect calculation of the elapsed time in response objects by ensuring the elapsed time is calculated in seconds. (first fixed release: 0.15.2).
Production impact:
  • If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).

Why This Breaks in Prod

  • The elapsed time was incorrectly calculated without converting to seconds
  • Production symptom (often without a traceback): The elapsed time reported was incoherent, leading to confusion in performance metrics.

Proof / Evidence

  • GitHub issue: #1310
  • Fix PR: https://github.com/encode/httpx/pull/1313
  • First fixed release: 0.15.2
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-09
  • Confidence: 0.85
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.69

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“### Checklist - [ X] The bug is reproducible against the latest release and/or master. - [ X] There are no similar issues or pull requests to fix it yet. ### Describe the bug The elapsed argument obtained following a stream request seems co”
Issue thread · issue description · source

Failure Signature (Search String)

  • The elapsed time reported was incoherent, leading to confusion in performance metrics.
Copy-friendly signature
signature.txt
Failure Signature ----------------- The elapsed time reported was incoherent, leading to confusion in performance metrics.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- The elapsed time reported was incoherent, leading to confusion in performance metrics.

Minimal Reproduction

repro.py
import httpx client = httpx.Client() with client.stream("GET", "https://httpbin.org/basic-auth/user/pass", auth=("user", "pass")) as r: print(r) print(r.elapsed)

Environment

  • httpx: 0.15.1

What Broke

The elapsed time reported was incoherent, leading to confusion in performance metrics.

Why It Broke

The elapsed time was incorrectly calculated without converting to seconds

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

Upgrade to version 0.15.2 or later.

When NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/encode/httpx/pull/1313

First fixed release: 0.15.2

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use if it changes public behavior or if the failure cannot be reproduced.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
  • Upgrade behind a canary and run integration tests against the canary before 100% rollout.
  • Add a TLS smoke test that performs a real handshake in CI (include CA bundle validation and hostname checks).
  • Alert on handshake failures by error string and endpoint to catch cert/CA changes quickly.

Version Compatibility Table

VersionStatus
0.15.2 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.