The Fix
Upgrade to version 0.22.0 or later.
Based on closed Kludex/uvicorn issue #675 · 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%.
@@ -104,6 +104,9 @@ Options:
is received within this timeout. [default:
5]
+ --timeout-graceful-shutdown INTEGER
+ Maximum number of seconds to wait for
+ graceful shutdown.
$ uvicorn <app> --debug
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [84365] using statreload
INFO: Started server process [84367]
INFO: Waiting for application startup.
INFO: Application startup complete.
.
.
.
.
WARNING: Detected file change in '<file>'. Reloading...
INFO: Shutting down
INFO: Waiting for background tasks to complete. (CTRL+C to force quit) <--- ???
^CINFO: Shutting down <--- Ctrl+C
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.22.0 or later.\nWhen NOT to use: This fix should not be used if graceful shutdown is required for ongoing tasks.\n\n
Why This Fix Works in Production
- Trigger: WARNING: Detected file change in '<file>'. Reloading...
- Mechanism: The server does not allow immediate shutdown when background tasks are running
- Why the fix works: Adds a `--timeout-graceful-shutdown` parameter to allow for graceful shutdown configuration from the command line, addressing issue #675. (first fixed release: 0.22.0).
- 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
- The server does not allow immediate shutdown when background tasks are running
- Production symptom (often without a traceback): WARNING: Detected file change in '<file>'. Reloading...
Proof / Evidence
- GitHub issue: #675
- Fix PR: https://github.com/kludex/uvicorn/pull/1950
- First fixed release: 0.22.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.58
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“I need this option. Could you please explain where you change the force_exit, is it in the source code ? Edit : it is in…”
“INFO Server running on [http://127.0.0.1:8000]. Press Ctrl+C to stop the server why my serve is not stop giving me reason”
“What I said on https://github.com/encode/uvicorn/issues/451#issuecomment-1367828755 also solves the issue here.”
“If we set --timeout-graceful-shutdown to 0, then this will be achieved. Let's do that. :+1:”
Failure Signature (Search String)
- WARNING: Detected file change in '<file>'. Reloading...
- supervisor = ChangeReload(config, target=server.run, sockets=[sock])
Copy-friendly signature
Failure Signature
-----------------
WARNING: Detected file change in '<file>'. Reloading...
supervisor = ChangeReload(config, target=server.run, sockets=[sock])
Error Message
Signature-only (no traceback captured)
Error Message
-------------
WARNING: Detected file change in '<file>'. Reloading...
supervisor = ChangeReload(config, target=server.run, sockets=[sock])
Minimal Reproduction
$ uvicorn <app> --debug
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [84365] using statreload
INFO: Started server process [84367]
INFO: Waiting for application startup.
INFO: Application startup complete.
.
.
.
.
WARNING: Detected file change in '<file>'. Reloading...
INFO: Shutting down
INFO: Waiting for background tasks to complete. (CTRL+C to force quit) <--- ???
^CINFO: Shutting down <--- Ctrl+C
What Broke
Developers experience delays in server reload due to infinite background tasks.
Why It Broke
The server does not allow immediate shutdown when background tasks are running
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.22.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/kludex/uvicorn/pull/1950
First fixed release: 0.22.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if graceful shutdown is required for ongoing tasks.
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 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.
- 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.22.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.