The Fix
Upgrade to version 0.14.2 or later.
Based on closed Kludex/starlette issue #1050 · PR/commit linked
@@ -217,15 +217,15 @@ def generate_html(self, exc: Exception, limit: int = 7) -> str:
exc, capture_locals=True
)
- frames = inspect.getinnerframes(
- traceback_obj.exc_traceback, limit # type: ignore
- )
Option A — Upgrade to fixed release\nUpgrade to version 0.14.2 or later.\nWhen NOT to use: Do not apply this fix if the context management behavior of sockets is intentionally modified.\n\n
Why This Fix Works in Production
- Trigger: ResourceWarnings are raised during the execution of the TestClient due to unclosed sockets.
- Mechanism: Various objects are not used in context managers, leading to unclosed sockets and ResourceWarnings
- Why the fix works: Fixes ResourceWarnings in TestClient by ensuring that sockets are properly closed. (first fixed release: 0.14.2).
Why This Breaks in Prod
- Various objects are not used in context managers, leading to unclosed sockets and ResourceWarnings
- Production symptom (often without a traceback): ResourceWarnings are raised during the execution of the TestClient due to unclosed sockets.
Proof / Evidence
- GitHub issue: #1050
- Fix PR: https://github.com/kludex/starlette/pull/1132
- First fixed release: 0.14.2
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.75
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.77
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“it looks like various objects are not used in context managers, or pass on the __exit__ to their super class”
Failure Signature (Search String)
- ResourceWarnings are raised during the execution of the TestClient due to unclosed sockets.
Copy-friendly signature
Failure Signature
-----------------
ResourceWarnings are raised during the execution of the TestClient due to unclosed sockets.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
ResourceWarnings are raised during the execution of the TestClient due to unclosed sockets.
What Broke
ResourceWarnings are raised during the execution of the TestClient due to unclosed sockets.
Why It Broke
Various objects are not used in context managers, leading to unclosed sockets and ResourceWarnings
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.14.2 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/starlette/pull/1132
First fixed release: 0.14.2
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not apply this fix if the context management behavior of sockets is intentionally modified.
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.14.2 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.