Jump to solution
Verify

The Fix

Upgrade to version 0.18.0 or later.

Based on closed Kludex/uvicorn issue #1305 · 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
@@ -1,5 +1,8 @@ -e .[standard] +# Type annotation +asgiref==3.5.2 +
repro.py
try: from asgiref.typing import WebSocketScope except ImportError: from asgiref.typing import WebsocketScope WebSocketScope = WebsocketScope
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.18.0 or later.\nWhen NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.\n\nOption C — Workaround\nuntil https://github.com/django/channels/issues/1722 is resolved?\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: Error: 1-03 17:27:52 +0000] [9] [ERROR] Exception in ASGI application
  • Mechanism: Removes the `asgiref` dependency and adds it to the `requirements.txt`, addressing the backward compatibility issue.
  • Why the fix works: Removes the `asgiref` dependency and adds it to the `requirements.txt`, addressing the backward compatibility issue. (first fixed release: 0.18.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

  • Shows up under Python 3.10 in real deployments (not just unit tests).
  • Surfaces as: Error: 1-03 17:27:52 +0000] [9] [ERROR] Exception in ASGI application

Proof / Evidence

  • GitHub issue: #1305
  • Fix PR: https://github.com/kludex/uvicorn/pull/1532
  • First fixed release: 0.18.0
  • 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.51

Discussion

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

“I'm not sure @Tony - that's a good question”
@lovelydinosaur · 2022-02-11 · confirmation · source
“I will keep this issue open for now > I'd certainly suggest closing #1373 off, yes. Can you clarify what's meant by closing it off?…”
@tony · 2022-02-11 · confirmation · source
“> Can you clarify what's meant by closing it off? Yes”
@lovelydinosaur · 2022-02-11 · confirmation · source
“I'm willing to approve a PR with the vendor, and tests running against asgiref.typing. :+1:”
@Kludex · 2022-01-08 · source

Failure Signature (Search String)

  • Error: 1-03 17:27:52 +0000] [9] [ERROR] Exception in ASGI application

Error Message

Stack trace
error.txt
Error Message ------------- Error: 1-03 17:27:52 +0000] [9] [ERROR] Exception in ASGI application Traceback (most recent call last): File "/opt/venv/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 376, in run_asgi result = await app(self.scope, self.receive, self.send) File "/opt/venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__ return await self.app(scope, receive, send) File "/opt/venv/lib/python3.10/site-packages/uvicorn/middleware/asgi2.py", line 17, in __call__ await instance(receive, send) File "/opt/venv/lib/python3.10/site-packages/channels/http.py", line 192, in __call__ await self.handle(body_stream) File "/opt/venv/lib/python3.10/site-packages/asgiref/sync.py", line 409, in __call__ raise RuntimeError( RuntimeError: Single thread executor already being used, would deadlock

Minimal Reproduction

repro.py
try: from asgiref.typing import WebSocketScope except ImportError: from asgiref.typing import WebsocketScope WebSocketScope = WebsocketScope

Environment

  • Python: 3.10

What Broke

Users experienced deadlock errors when serving static files under heavy load.

Fix Options (Details)

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

Upgrade to version 0.18.0 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.

Option C — Workaround Temporary workaround

until https://github.com/django/channels/issues/1722 is resolved?

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

Use only if you cannot change versions today. Treat this as a stopgap and remove once upgraded.

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

First fixed release: 0.18.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

  • Do not use if it changes public behavior or if the failure cannot be reproduced.
  • 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.18.0 Fixed

Related Issues

No related fixes found.

Sources

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