Jump to solution
Verify

The Fix

Upgrade to version 0.17.0 or later.

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

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Jump to Verify Open PR/Commit
@@ -64,7 +64,6 @@ logger = get_logger(__name__) -KEEPALIVE_EXPIRY = 5.0 USER_AGENT = f"python-httpx/{__version__}" ACCEPT_ENCODING = ", ".join(
repro.py
import httpcore import httpx ssl_context = httpx.create_ssl_context() transport = httpcore.SyncConnectionPool( ssl_context=ssl_context, max_connections=100, max_keepalive_connections=20, keepalive_expiry=10.0, # <--- ) with httpx.Client(transport=transport): ...
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.17.0 or later.\nWhen NOT to use: This fix is not suitable if the application can tolerate the default Keep-Alive timeout.\n\n

Why This Fix Works in Production

  • Trigger: Customize Keep-Alive timeout
  • Mechanism: The default Keep-Alive timeout was set to 5 seconds, causing premature connection drops
  • Why the fix works: Added a configurable keepalive_expiry option to the Limits configuration in httpx. (first fixed release: 0.17.0).
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • The default Keep-Alive timeout was set to 5 seconds, causing premature connection drops
  • Production symptom (often without a traceback): Customize Keep-Alive timeout

Proof / Evidence

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

Discussion

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

“Thanks for the suggestion, I'll definitely give it a try as redoing the authentication every 1-2 minute of idle connections is a lot more desirable…”
@jborean93 · 2020-11-23 · source
“> "either expired or disconnected policy" True”
@florimondmanca · 2020-11-23 · source
“Okay, so..”
@lovelydinosaur · 2020-11-23 · source
“Hello! This idea was actually mentioned and quickly discussed on the original PR, see https://github.com/encode/httpx/pull/627#discussion_r356569051 :-) > Should this be made configurable, e.g”
@florimondmanca · 2020-11-23 · source

Failure Signature (Search String)

  • Customize Keep-Alive timeout
  • The change https://github.com/encode/httpx/pull/627 added a 5 second timeout for Keep-Alive connections. Once that timeout is reached and no new requests are made in that
Copy-friendly signature
signature.txt
Failure Signature ----------------- Customize Keep-Alive timeout The change https://github.com/encode/httpx/pull/627 added a 5 second timeout for Keep-Alive connections. Once that timeout is reached and no new requests are made in that timeframe then the connection in the pool is dropped.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Customize Keep-Alive timeout The change https://github.com/encode/httpx/pull/627 added a 5 second timeout for Keep-Alive connections. Once that timeout is reached and no new requests are made in that timeframe then the connection in the pool is dropped.

Minimal Reproduction

repro.py
import httpcore import httpx ssl_context = httpx.create_ssl_context() transport = httpcore.SyncConnectionPool( ssl_context=ssl_context, max_connections=100, max_keepalive_connections=20, keepalive_expiry=10.0, # <--- ) with httpx.Client(transport=transport): ...

What Broke

Clients experienced frequent connection drops leading to expensive re-authentication processes.

Why It Broke

The default Keep-Alive timeout was set to 5 seconds, causing premature connection drops

Fix Options (Details)

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

Upgrade to version 0.17.0 or later.

When NOT to use: This fix is not suitable if the application can tolerate the default Keep-Alive timeout.

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/1398

First fixed release: 0.17.0

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

  • This fix is not suitable if the application can tolerate the default Keep-Alive timeout.

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.17.0 Fixed

Related Issues

No related fixes found.

Sources

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