The Fix
pip install fastapi==0.115.6
Based on closed fastapi/fastapi issue #13067 · PR/commit linked
Production note: This tends to surface only under concurrency. Reproduce with load tests and watch for lock contention/cancellation paths.
@@ -1,7 +1,7 @@
from typing import AsyncGenerator, ContextManager, TypeVar
-import anyio
+import anyio.to_thread
from anyio import CapacityLimiter
File "...3.11/lib/python3.11/contextlib.py", line 650, in enter_async_context
result = await _enter(cm)
^^^^^^^^^^^^^^^^
File "...3.11/lib/python3.11/contextlib.py", line 210, in __aenter__
return await anext(self.gen)
^^^^^^^^^^^^^^^^^^^^^
File ".../full-stack-fastapi-template/backend/.venv/lib/python3.11/site-packages/fastapi/concurrency.py", line 35, in contextmanager_in_threadpool
raise e
Exception: error
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\npip install fastapi==0.115.6\nWhen NOT to use: This fix should not be applied if the application does not use synchronous dependencies with yield.\n\n
Why This Fix Works in Production
- Trigger: poor quality traceback / useful stack frames not present when exceptions raised in sync dependencies
- Mechanism: The traceback was missing when exceptions were raised in synchronous dependencies using yield
- Why the fix works: Preserves the traceback when an exception is raised in a synchronous dependency with yield, addressing the issue of missing traceback information. (first fixed release: 0.115.6).
- If left unfixed, failures can be intermittent under concurrency (hard to reproduce; shows up as sporadic 5xx/timeouts).
Why This Breaks in Prod
- Shows up under Python 3.11 in real deployments (not just unit tests).
- The traceback was missing when exceptions were raised in synchronous dependencies using yield
- Surfaces as: File "...3.11/lib/python3.11/contextlib.py", line 650, in enter_async_context\n result = await _enter(cm)\n ^^^^^^^^^^^^^^^^\n File "...3.11/lib/python3.11/contextlib.py", line…
Proof / Evidence
- GitHub issue: #13067
- Fix PR: https://github.com/fastapi/fastapi/pull/5823
- First fixed release: 0.115.6
- Reproduced locally: No (not executed)
- Last verified: 2026-02-08
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.56
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Close enough: Dropped a breakpoint, does indeed appear that __traceback__ is None, but why?”
“@Kludex - about the issue/discussions thing..”
“I don't really have the power or motivation to do that. **I don't maintain FastAPI.** If you want, you can create a GitHub issue about…”
“For reference, this issue was solved in the last release: https://github.com/fastapi/fastapi/releases/tag/0.115.6 - Specifically on https://github.com/fastapi/fastapi/pull/5823”
Failure Signature (Search String)
- poor quality traceback / useful stack frames not present when exceptions raised in sync dependencies
Error Message
Stack trace
Error Message
-------------
File "...3.11/lib/python3.11/contextlib.py", line 650, in enter_async_context\n result = await _enter(cm)\n ^^^^^^^^^^^^^^^^\n File "...3.11/lib/python3.11/contextlib.py", line 210, in __aenter__\n return await anext(self.gen)\n ^^^^^^^^^^^^^^^^^^^^^\n File ".../full-stack-fastapi-template/backend/.venv/lib/python3.11/site-packages/fastapi/concurrency.py", line 35, in contextmanager_in_threadpool\n raise e
Minimal Reproduction
File "...3.11/lib/python3.11/contextlib.py", line 650, in enter_async_context
result = await _enter(cm)
^^^^^^^^^^^^^^^^
File "...3.11/lib/python3.11/contextlib.py", line 210, in __aenter__
return await anext(self.gen)
^^^^^^^^^^^^^^^^^^^^^
File ".../full-stack-fastapi-template/backend/.venv/lib/python3.11/site-packages/fastapi/concurrency.py", line 35, in contextmanager_in_threadpool
raise e
Exception: error
Environment
- Python: 3.11
What Broke
Developers received unhelpful tracebacks, making debugging difficult during development.
Why It Broke
The traceback was missing when exceptions were raised in synchronous dependencies using yield
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install fastapi==0.115.6
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/fastapi/fastapi/pull/5823
First fixed release: 0.115.6
Last verified: 2026-02-08. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if the application does not use synchronous dependencies with yield.
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.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.115.6 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.