The Fix
Upgrade to version 0.15.0 or later.
Based on closed Kludex/starlette issue #1012 · PR/commit linked
@@ -22,7 +22,7 @@
Starlette is a lightweight [ASGI](https://asgi.readthedocs.io/en/latest/) framework/toolkit,
-which is ideal for building high performance asyncio services.
+which is ideal for building high performance async services.
Option A — Upgrade to fixed release\nUpgrade to version 0.15.0 or later.\nWhen NOT to use: This fix should not be applied if the application requires unbounded queue behavior for streaming responses.\n\n
Why This Fix Works in Production
- Trigger: In my mind setting a `maxsize` of eg 10 would resolve the memory issues to you’re seeing, because then if the client isn’t consuming chunks fast enough the app…
- Mechanism: The unbounded asyncio queue in BaseHTTPMiddleware causes excessive memory usage during large streaming responses
- Why the fix works: Limits the queue size to 1 in the BaseHTTPMiddleware to prevent high memory usage when streaming large responses. (first fixed release: 0.15.0).
- If left unfixed, failures can be intermittent under concurrency (hard to reproduce; shows up as sporadic 5xx/timeouts).
Why This Breaks in Prod
- The unbounded asyncio queue in BaseHTTPMiddleware causes excessive memory usage during large streaming responses
- Production symptom (often without a traceback): In my mind setting a `maxsize` of eg 10 would resolve the memory issues to you’re seeing, because then if the client isn’t consuming chunks fast enough the app will block on `send()` until there’s room in the queue.
Proof / Evidence
- GitHub issue: #1012
- Fix PR: https://github.com/encode/starlette/pull/1157
- First fixed release: 0.15.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.70
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@via Starlette version 0.13.7 has been released to address this issue.”
“I believe this should be fixed by #1157”
“For a bit of background, the BaseHTTPMiddleware offers a way for users to write middleware that takes a request and builds a response”
“@erewok thank you for the information! We have been using a similar change (queue size of 3), and were going to try the PR you…”
Failure Signature (Search String)
- In my mind setting a `maxsize` of eg 10 would resolve the memory issues to you’re seeing, because then if the client isn’t consuming chunks fast enough the app will block on
- We have been using a similar change (queue size of 3), and were going to try the PR you referenced. We will just update and can report back. Thank you for the speedy responses.
Copy-friendly signature
Failure Signature
-----------------
In my mind setting a `maxsize` of eg 10 would resolve the memory issues to you’re seeing, because then if the client isn’t consuming chunks fast enough the app will block on `send()` until there’s room in the queue.
We have been using a similar change (queue size of 3), and were going to try the PR you referenced. We will just update and can report back. Thank you for the speedy responses.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
In my mind setting a `maxsize` of eg 10 would resolve the memory issues to you’re seeing, because then if the client isn’t consuming chunks fast enough the app will block on `send()` until there’s room in the queue.
We have been using a similar change (queue size of 3), and were going to try the PR you referenced. We will just update and can report back. Thank you for the speedy responses.
What Broke
Memory consumption grows indefinitely, leading to kernel out-of-memory errors during large response streaming.
Why It Broke
The unbounded asyncio queue in BaseHTTPMiddleware causes excessive memory usage during large streaming responses
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.15.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/encode/starlette/pull/1157
First fixed release: 0.15.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if the application requires unbounded queue behavior for streaming responses.
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.
- Track RSS + object counts after deployments; alert on monotonic growth and GC pressure.
- Add a long-running test that repeats the failing call path and asserts stable memory.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.15.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.