The Fix
Upgrade to version 0.11.4 or later.
Based on closed Kludex/uvicorn issue #184 · 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%.
@@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
from uvicorn.config import Config
-from uvicorn.main import main, run, Server
+from uvicorn.main import Server, main, run
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
PIDFile=/run/gunicorn/pid
User=deploy
Group=deploy
RuntimeDirectory=gunicorn
WorkingDirectory=/home/deploy/django/
ExecStart=/usr/local/bin/gunicorn app.asgi:application --worker-class uvicorn.workers.UvicornWorker --pid /run/gunicorn/pid --bind unix:/run/gunicorn/socket --workers 4 --preload
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
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.11.4 or later.\nWhen NOT to use: This fix should not be applied if using a different worker class or application server.\n\n
Why This Fix Works in Production
- Trigger: Error while closing socket [Errno 9] Bad file descriptor
- Mechanism: Improper setup of the event loop in Gunicorn worker class leading to socket errors
- Why the fix works: Finesse Gunicorn loop setup to resolve issues with socket errors. (first fixed release: 0.11.4).
- 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.6 in real deployments (not just unit tests).
- Improper setup of the event loop in Gunicorn worker class leading to socket errors
- Surfaces as: Error while closing socket [Errno 9] Bad file descriptor
Proof / Evidence
- GitHub issue: #184
- Fix PR: https://github.com/kludex/uvicorn/pull/312
- 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.58
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“> /usr/local/lib/python3.6/dist-packages/daphne/server.py Are you running daphne or uvicorn, here? Did you mean to report this on the uvicorn issues?”
“@tomchristie that line is about a bug with raven package (Sentry) and Django Channels, it does not have anything to do with uvicorn”
“Somewhat confused by the issue, since running daphne under gunicorn doesn't make sense as far as I can see? (It doens't include a gunicorn worker…”
“Django channels has dependency requirement with daphne, warning issue: https://github.com/django/daphne/issues/195”
Failure Signature (Search String)
- Error while closing socket [Errno 9] Bad file descriptor
Error Message
Stack trace
Error Message
-------------
Error while closing socket [Errno 9] Bad file descriptor
Minimal Reproduction
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
PIDFile=/run/gunicorn/pid
User=deploy
Group=deploy
RuntimeDirectory=gunicorn
WorkingDirectory=/home/deploy/django/
ExecStart=/usr/local/bin/gunicorn app.asgi:application --worker-class uvicorn.workers.UvicornWorker --pid /run/gunicorn/pid --bind unix:/run/gunicorn/socket --workers 4 --preload
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Environment
- Python: 3.6
What Broke
Frequent socket errors causing worker exits and delayed responses.
Why It Broke
Improper setup of the event loop in Gunicorn worker class leading to socket errors
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.11.4 or later.
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/kludex/uvicorn/pull/312
First fixed release: 0.11.4
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if using a different worker class or application server.
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
- Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
- Pin production dependencies and upgrade only with a reproducible test that hits the failing path.
Version Compatibility Table
| Version | Status |
|---|---|
| 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.