Jump to solution
Verify

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%.

Jump to Verify Open PR/Commit
@@ -7,6 +7,7 @@ import sys import typing +import warnings from concurrent.futures import Future from types import GeneratorType
repro.py
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"}
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
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).
Production impact:
  • 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
affected (exit=None)
fixed (exit=0)

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”
@lovelydinosaur · 2022-02-08 · confirmation · source
“I have a case where a "timeout" would be useful in testing how the server handles disconnecting clients”
@logi · 2022-09-06 · source
“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.”
@Kludex · 2025-01-04 · source
“> I have a case where a "timeout" would be useful in testing how the server handles disconnecting clients”
@Kludex · 2022-09-06 · source

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
signature.txt
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.txt
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

repro.py
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.

When NOT to use: Do not use the timeout parameter if you expect it to function as in the requests package.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

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

verify
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

VersionStatus
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.