The Fix
Upgrade to version 0.7.2 or later.
Based on closed encode/httpx issue #140 · PR/commit linked
Production note: Watch p95/p99 latency and retry volume; timeouts can turn into retry storms and duplicate side-effects.
@@ -1,4 +1,3 @@
@@ -1,4 +1,3 @@
-from .adapters.redirects import RedirectAdapter
from .backends.sync import SyncClient
from .client import Client
class LoggingHTTPAdapter(requests.adapters.HTTPAdapter):
"""Adapter to log request and response."""
def send(self, request, *args, **kwargs):
sensitive_params = conf.SENSITIVE_PARAMS
# transaction ID to identify the logs.
trans_id = util.generate_uuid()
headers = util.filter_sensitive_information(
request.headers, sensitive_params
)
log.info(f"<{trans_id}> Request: {request.method} {request.url}")
log.info(f"<{trans_id}> Request headers: {headers}")
log.info(f"<{trans_id}> Request body: {request.body}")
resp = super().send(request, *args, **kwargs)
headers = util.filter_sensitive_information(
resp.headers, sensitive_params
)
log.info(f"<{trans_id}> Response: {resp.status_code} {resp.reason}")
log.info(f"<{trans_id}> Response headers: {headers}")
log.info(f"<{trans_id}> Response body: {resp.content}")
# Store the transaction ID in the response object, so that it can be
# added to the logs from test cases.
resp.__dict__["transaction_id"] = trans_id
return resp
def mount_adapter(session):
# currently we only have TimeoutHTTPAdapter and LoggingHTTPAdapter,
# when we add more in the future, we can use this function to mount
# our adapters.
adapters = [LoggingHTTPAdapter()]
for adapter in adapters:
session.mount("http://", adapter)
session.mount("https://", adapter)
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\nUpgrade to version 0.7.2 or later.\nWhen NOT to use: This fix is not suitable for users requiring the old adapter system.\n\n
Why This Fix Works in Production
- Trigger: Users were unable to implement custom logging adapters effectively.
- Mechanism: Refactored the adapter system to improve flexibility and maintainability
- Why the fix works: Refactored the adapter system to improve flexibility and maintainability. (first fixed release: 0.7.2).
- If left unfixed, tail latency can spike under load and surface as timeouts/retries (amplifying incident impact).
Why This Breaks in Prod
- Refactored the adapter system to improve flexibility and maintainability
- Production symptom (often without a traceback): Users were unable to implement custom logging adapters effectively.
Proof / Evidence
- GitHub issue: #140
- Fix PR: https://github.com/encode/httpx/pull/55
- First fixed release: 0.7.2
- 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.44
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“The Dispatcher interface is a very close equivalent to the Adapter interface”
“Excellent. I'll give that a shot tomorrow. Thanks!”
“This issue is no longer needed it seems? Reopen if I'm wrong here :)”
“Yup, the custom Dispatcher worked for me, was going to update on Monday once I had a bit more testing done. Good to close :+1:”
Failure Signature (Search String)
- Users were unable to implement custom logging adapters effectively.
Copy-friendly signature
Failure Signature
-----------------
Users were unable to implement custom logging adapters effectively.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Users were unable to implement custom logging adapters effectively.
Minimal Reproduction
class LoggingHTTPAdapter(requests.adapters.HTTPAdapter):
"""Adapter to log request and response."""
def send(self, request, *args, **kwargs):
sensitive_params = conf.SENSITIVE_PARAMS
# transaction ID to identify the logs.
trans_id = util.generate_uuid()
headers = util.filter_sensitive_information(
request.headers, sensitive_params
)
log.info(f"<{trans_id}> Request: {request.method} {request.url}")
log.info(f"<{trans_id}> Request headers: {headers}")
log.info(f"<{trans_id}> Request body: {request.body}")
resp = super().send(request, *args, **kwargs)
headers = util.filter_sensitive_information(
resp.headers, sensitive_params
)
log.info(f"<{trans_id}> Response: {resp.status_code} {resp.reason}")
log.info(f"<{trans_id}> Response headers: {headers}")
log.info(f"<{trans_id}> Response body: {resp.content}")
# Store the transaction ID in the response object, so that it can be
# added to the logs from test cases.
resp.__dict__["transaction_id"] = trans_id
return resp
def mount_adapter(session):
# currently we only have TimeoutHTTPAdapter and LoggingHTTPAdapter,
# when we add more in the future, we can use this function to mount
# our adapters.
adapters = [LoggingHTTPAdapter()]
for adapter in adapters:
session.mount("http://", adapter)
session.mount("https://", adapter)
What Broke
Users were unable to implement custom logging adapters effectively.
Why It Broke
Refactored the adapter system to improve flexibility and maintainability
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.7.2 or later.
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Option D — Guard side-effects with OnceOnly Guardrail for side-effects
Mitigate duplicate external side-effects under retries/timeouts/agent loops by gating the operation before calling external systems.
- Place OnceOnly between your code/agent and real side-effects (Stripe, emails, CRM, APIs).
- Use a stable key per side-effect (e.g., customer_id + action + idempotency_key).
- Fail-safe: configure fail-open vs fail-closed based on blast radius and spend risk.
Show example snippet (optional)
from onceonly import OnceOnly
import os
once = OnceOnly(api_key=os.environ["ONCEONLY_API_KEY"], fail_open=True)
# Stable idempotency key per real side-effect.
# Use a request id / job id / webhook delivery id / Stripe event id, etc.
event_id = "evt_..." # replace
key = f"stripe:webhook:{event_id}"
res = once.check_lock(key=key, ttl=3600)
if res.duplicate:
return {"status": "already_processed"}
# Safe to execute the side-effect exactly once.
handle_event(event_id)
Fix reference: https://github.com/encode/httpx/pull/55
First fixed release: 0.7.2
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not suitable for users requiring the old adapter system.
- Do not use this to hide logic bugs or data corruption. Use it to block duplicate external side-effects and enforce tool permissions/spend caps.
Verify Fix
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.
- Track RSS + object counts after deployments; alert on monotonic growth and GC pressure.
- Add a long-running test that repeats the failing call path and asserts stable memory.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.7.2 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.