Jump to solution
Verify

The Fix

Upgrade to version 0.11.4 or later.

Based on closed Kludex/uvicorn issue #241 · PR/commit linked

Production note: This tends to surface only under concurrency. Reproduce with load tests and watch for lock contention/cancellation paths.

Jump to Verify Open PR/Commit
@@ -507,9 +507,10 @@ async def receive(self): self.waiting_for_100_continue = False - self.flow.resume_reading() - await self.message_event.wait() - self.message_event.clear()
repro.py
I can replicate in both h11 and httptools. Hey guys! @pgjones your snippet looks similar to #250. In my case I trigger issue by sending a multipart file upload payload with cURL and it doesn't like what it gets back. Is there a connection? 🤔 Simpler replication: **script**
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.11.4 or later.\nWhen NOT to use: Do not apply this fix if the application does not utilize ASGI or if it requires a different handling of disconnect messages.\n\n

Why This Fix Works in Production

  • Trigger: Likely race condition with keep-alive http handling
  • Mechanism: A race condition occurs when handling disconnect messages in the ASGI application
  • Why the fix works: Fixes a race condition with disconnect messages in the ASGI application, addressing issue #241. (first fixed release: 0.11.4).
Production impact:
  • If left unfixed, failures can be intermittent under concurrency (hard to reproduce; shows up as sporadic 5xx/timeouts).

Why This Breaks in Prod

  • A race condition occurs when handling disconnect messages in the ASGI application
  • Production symptom (often without a traceback): Likely race condition with keep-alive http handling

Proof / Evidence

  • GitHub issue: #241
  • Fix PR: https://github.com/kludex/uvicorn/pull/281
  • First fixed release: 0.11.4
  • 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.67

Discussion

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

“I forgot to emphasize that this is very hard to see without a body, so I use this script with wrk,”
@pgjones · 2018-11-06 · source
“Thanks @pgjones, much appreciated! Are you able to replicate this at debug level? It'd help if we could unpick the very last few ASGI messages…”
@lovelydinosaur · 2018-11-07 · source
“I think this is the relevant part from wrk -d 10s -s scripts/post.lua http://localhost:8000, I can replicate in both h11 and httptools.”
@pgjones · 2018-11-10 · source
“Hey guys! @pgjones your snippet looks similar to #250. In my case I trigger issue by sending a multipart file upload payload with cURL and…”
@superduper · 2018-11-20 · source

Failure Signature (Search String)

  • Likely race condition with keep-alive http handling
  • await asyncio.sleep(0) # This line is sufficient to break Uvicorn serving
Copy-friendly signature
signature.txt
Failure Signature ----------------- Likely race condition with keep-alive http handling await asyncio.sleep(0) # This line is sufficient to break Uvicorn serving

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Likely race condition with keep-alive http handling await asyncio.sleep(0) # This line is sufficient to break Uvicorn serving

Minimal Reproduction

repro.py
I can replicate in both h11 and httptools. Hey guys! @pgjones your snippet looks similar to #250. In my case I trigger issue by sending a multipart file upload payload with cURL and it doesn't like what it gets back. Is there a connection? 🤔 Simpler replication: **script**

What Broke

The application may hang or fail to respond to HTTP requests under certain conditions.

Why It Broke

A race condition occurs when handling disconnect messages in the ASGI application

Fix Options (Details)

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

Upgrade to version 0.11.4 or later.

When NOT to use: Do not apply this fix if the application does not utilize ASGI or if it requires a different handling of disconnect messages.

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)
onceonly.py
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)

See OnceOnly SDK

When NOT to use: 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.

Fix reference: https://github.com/kludex/uvicorn/pull/281

First fixed release: 0.11.4

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 apply this fix if the application does not utilize ASGI or if it requires a different handling of disconnect messages.
  • 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

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 stress test that runs high-concurrency workloads and fails on thread dumps / blocked locks.
  • Enable watchdog dumps in prod (faulthandler, thread dump endpoint) to capture deadlocks quickly.

Version Compatibility Table

VersionStatus
0.11.4 Fixed

Related Issues

No related fixes found.

Sources

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