Jump to solution
Verify

The Fix

Upgrade to version 0.23.1 or later.

Based on closed Kludex/starlette issue #1977 · 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
@@ -89,8 +89,6 @@ async def body_stream() -> typing.AsyncGenerator[bytes, None]: if body: yield body - if not message.get("more_body", False): - break
repro.py
import uvicorn from fastapi import FastAPI from starlette.middleware.base import BaseHTTPMiddleware app = FastAPI() @app.get("/info") def info(): # raises Exception as expected, the traceback is seen in console raise Exception private_api = FastAPI() @private_api.get("/info") def info(): # exception is handled silently, no traceback is seen in console raise Exception app.mount("/private", private_api) class Middleware(BaseHTTPMiddleware): async def dispatch(self, request, call_next): return await call_next(request) app.add_middleware(Middleware) # when this is removed, the exceptions are raised for all routes if __name__ == '__main__': uvicorn.run(app, port=8000)
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.23.1 or later.\nWhen NOT to use: Do not use this fix if middleware behavior is expected to suppress exceptions intentionally.\n\n

Why This Fix Works in Production

  • Trigger: middleware causes exceptions to not be raised/handled silently
  • Mechanism: Exceptions raised on subapps were not propagated correctly due to middleware handling
  • Why the fix works: Resolves the issue where exceptions raised on a subapp are not propagated correctly when using middleware. (first fixed release: 0.23.1).
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

  • Exceptions raised on subapps were not propagated correctly due to middleware handling
  • Production symptom (often without a traceback): middleware causes exceptions to not be raised/handled silently

Proof / Evidence

  • GitHub issue: #1977
  • Fix PR: https://github.com/kludex/starlette/pull/1940
  • First fixed release: 0.23.1
  • 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.49

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“Probably introduced by https://github.com/encode/starlette/pull/1715, if not... Maybe https://github.com/encode/starlette/pull/1649? cc @adriangb”
@Kludex · 2022-12-06 · source
“It was none of those PRs. This was cased by https://github.com/encode/starlette/pull/1609. Solution on #1940.”
@Kludex · 2022-12-06 · source
“I'm experiencing this issue as well since the upgrade to starlette >= 0.28”
@odelmarcelle · 2024-02-25 · source

Failure Signature (Search String)

  • middleware causes exceptions to not be raised/handled silently
  • When exceptions are raised on a subapp, the exceptions are not propagated all the way to see in console
Copy-friendly signature
signature.txt
Failure Signature ----------------- middleware causes exceptions to not be raised/handled silently When exceptions are raised on a subapp, the exceptions are not propagated all the way to see in console

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- middleware causes exceptions to not be raised/handled silently When exceptions are raised on a subapp, the exceptions are not propagated all the way to see in console

Minimal Reproduction

repro.py
import uvicorn from fastapi import FastAPI from starlette.middleware.base import BaseHTTPMiddleware app = FastAPI() @app.get("/info") def info(): # raises Exception as expected, the traceback is seen in console raise Exception private_api = FastAPI() @private_api.get("/info") def info(): # exception is handled silently, no traceback is seen in console raise Exception app.mount("/private", private_api) class Middleware(BaseHTTPMiddleware): async def dispatch(self, request, call_next): return await call_next(request) app.add_middleware(Middleware) # when this is removed, the exceptions are raised for all routes if __name__ == '__main__': uvicorn.run(app, port=8000)

What Broke

Exceptions in subapps fail silently, leading to missing stack traces in logs.

Why It Broke

Exceptions raised on subapps were not propagated correctly due to middleware handling

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

Upgrade to version 0.23.1 or later.

When NOT to use: Do not use this fix if middleware behavior is expected to suppress exceptions intentionally.

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/1940

First fixed release: 0.23.1

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 this fix if middleware behavior is expected to suppress exceptions intentionally.

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

  • 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

VersionStatus
0.23.1 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.