The Fix
Upgrade to version 0.46.0 or later.
Based on closed Kludex/starlette issue #1108 · 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%.
@@ -7,6 +7,7 @@
import sys
import typing
+import warnings
from concurrent.futures import Future
from types import GeneratorType
import time
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.testclient import TestClient
mock_service = Starlette()
@mock_service.route("/slow_response")
def slow_response(request):
time.sleep(0.01)
return JSONResponse({"mock": "slow example"})
def test_timeout():
""" no timeout exception raised -- this test passes when it should fail """
client = TestClient(mock_service, raise_server_exceptions=True)
response = client.get("/slow_response", timeout=0.001)
assert response.json() == {"mock": "slow example"}
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.46.0 or later.\nWhen NOT to use: Do not use the timeout parameter if you expect it to function as in the requests package.\n\n
Why This Fix Works in Production
- Trigger: TestClient.request does not honor timeout
- Mechanism: Added basic timeout support for TestClient, addressing issue #1108.
- Why the fix works: Added basic timeout support for TestClient, addressing issue #1108. (first fixed release: 0.46.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
- Production symptom (often without a traceback): TestClient.request does not honor timeout
Proof / Evidence
- GitHub issue: #1108
- Fix PR: https://github.com/kludex/starlette/pull/2840
- First fixed release: 0.46.0
- 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.51
Verified Execution
We executed the runnable minimal repro in a temporary environment and captured exit codes + logs.
- Status: PASS
- Ran: 2026-02-11T16:52:29Z
- Package: starlette
- Fixed: 0.46.0
- Mode: fixed_only
- Outcome: ok
Logs
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Closing as per https://github.com/encode/starlette/pull/1109 timeouts == flaky tests”
“I have a case where a "timeout" would be useful in testing how the server handles disconnecting clients”
“Since the timeout is not doing anything, let's add a deprecation warning explaining it doesn't work, and remove the parameter in some time.”
“> I have a case where a "timeout" would be useful in testing how the server handles disconnecting clients”
Failure Signature (Search String)
- TestClient.request does not honor timeout
- `timeout` parameter exposed in `testclient.request` has no effect. Looking through the code, it seems as though we use the same interface as `requests` package but only a subset
Copy-friendly signature
Failure Signature
-----------------
TestClient.request does not honor timeout
`timeout` parameter exposed in `testclient.request` has no effect. Looking through the code, it seems as though we use the same interface as `requests` package but only a subset of those features are supported by `testclient`
Error Message
Signature-only (no traceback captured)
Error Message
-------------
TestClient.request does not honor timeout
`timeout` parameter exposed in `testclient.request` has no effect. Looking through the code, it seems as though we use the same interface as `requests` package but only a subset of those features are supported by `testclient`
Minimal Reproduction
import time
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.testclient import TestClient
mock_service = Starlette()
@mock_service.route("/slow_response")
def slow_response(request):
time.sleep(0.01)
return JSONResponse({"mock": "slow example"})
def test_timeout():
""" no timeout exception raised -- this test passes when it should fail """
client = TestClient(mock_service, raise_server_exceptions=True)
response = client.get("/slow_response", timeout=0.001)
assert response.json() == {"mock": "slow example"}
What Broke
Timeout exceptions were not raised during integration tests, leading to false positives.
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.46.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/starlette/pull/2840
First fixed release: 0.46.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use the timeout parameter if you expect it to function as in the requests package.
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 TLS smoke test that performs a real handshake in CI (include CA bundle validation and hostname checks).
- Alert on handshake failures by error string and endpoint to catch cert/CA changes quickly.
- 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.46.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.