The Fix
Upgrade to version 0.13.0 or later.
Based on closed encode/httpx issue #551 · PR/commit linked
Production note: Watch p95/p99 latency and retry volume; timeouts can turn into retry storms and duplicate side-effects.
@@ -77,6 +77,7 @@ def __init__(
self.stream_writer = stream_writer
self.read_lock = asyncio.Lock()
+ self.write_lock = asyncio.Lock()
self._inner: typing.Optional[SocketStream] = None
from quart import Quart, request
app = Quart(__name__)
@app.route("/", methods=["POST"])
async def post() -> dict:
data = await request.get_data()
return {"size": len(data)}
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
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.13.0 or later.\nWhen NOT to use: Do not apply this fix if using non-HTTP/2 configurations.\n\n
Why This Fix Works in Production
- Trigger: asyncio.get_event_loop().run_until_complete(cl.embedd_batch())
- Mechanism: Race conditions in HTTP/2 communication due to lack of locking around stream operations
- Why the fix works: Lock around stream.write and stream.close operations to prevent race conditions in HTTP/2 communication. (first fixed release: 0.13.0).
- If left unfixed, tail latency can spike under load and surface as timeouts/retries (amplifying incident impact).
Why This Breaks in Prod
- Shows up under Python 3.7 in real deployments (not just unit tests).
- Race conditions in HTTP/2 communication due to lack of locking around stream operations
- Surfaces as: Traceback (most recent call last):
Proof / Evidence
- GitHub issue: #551
- Fix PR: https://github.com/encode/httpx/pull/699
- First fixed release: 0.13.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.39
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“I can confirm that this issue is fixed with the master branch. Probably it is the consequence of one of the changes.”
“For housekeeping I'll close this, pending confirmation.”
“Expect this to have been closed in master via #612, but happy to reopen if I've made an incorrect assessment there.”
“Sorry, but it is not fixed with #612 the issue still persists. The example from the above still fails with the same error as before.…”
Failure Signature (Search String)
- asyncio.get_event_loop().run_until_complete(cl.embedd_batch())
Error Message
Stack trace
Error Message
-------------
Traceback (most recent call last):
File "/Users/primoz/PycharmProjects/orange3-imageanalytics/example.py", line 57, in <module>
asyncio.get_event_loop().run_until_complete(cl.embedd_batch())
File "/Users/primoz/miniconda3/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "/Users/primoz/PycharmProjects/orange3-imageanalytics/example.py", line 19, in embedd_batch
embeddings = await asyncio.gather(*requests)
File "/Users/primoz/PycharmProjects/orange3-imageanalytics/example.py", line 43, in _send_to_server
emb = await self._send_request(client, im, url)
File "/Users/primoz/PycharmProjects/orange3-imageanalytics/example.py", line 50, in _send_request
response = await client.post(url, headers=headers, data=image)
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/client.py", line 492, in post
trust_env=trust_env,
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/client.py", line 634, in request
trust_env=trust_env,
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/client.py", line 658, in send
trust_env=trust_env,
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/client.py", line 273, in _get_response
return await get_response(request)
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/middleware/redire
... (truncated) ...
Minimal Reproduction
from quart import Quart, request
app = Quart(__name__)
@app.route("/", methods=["POST"])
async def post() -> dict:
data = await request.get_data()
return {"size": len(data)}
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
Environment
- Python: 3.7
What Broke
Users experience intermittent assertion errors during HTTP/2 requests.
Why It Broke
Race conditions in HTTP/2 communication due to lack of locking around stream operations
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.13.0 or later.
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/699
First fixed release: 0.13.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not apply this fix if using non-HTTP/2 configurations.
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.
- Make timeouts explicit and test them (unit + integration) to avoid silent behavior changes.
- Instrument retries (attempt count + reason) and alert on spikes to catch dependency slowdowns.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.13.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.