Jump to solution
Verify

The Fix

Upgrade to version 0.13.4 or later.

Based on closed Kludex/starlette issue #483 · 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
@@ -6,7 +6,7 @@ from starlette.datastructures import MutableHeaders, Secret -from starlette.requests import Request +from starlette.requests import HTTPConnection from starlette.types import ASGIApp, Message, Receive, Scope, Send
repro.py
Traceback (most recent call last): File ".venv/lib/python3.7/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 146, in run_asgi asgi = self.app(self.scope) File ".venv/lib/python3.7/site-packages/starlette/applications.py", line 134, in __call__ return self.error_middleware(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/errors.py", line 88, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 37, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/base.py", line 22, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/base.py", line 22, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/exceptions.py", line 49, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/routing.py", line 587, in __call__ return route(scope) File ".venv/lib/python3.7/site-packages/starlette/routing.py", line 356, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/applications.py", line 134, in __call__ return self.error_middleware(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/errors.py", line 88, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/sessions.py", line 34, in __call__ request = Request(scope) File ".venv/lib/python3.7/site-packages/starlette/requests.py", line 128, in __init__ assert scope["type"] == "http"
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.13.4 or later.\nWhen NOT to use: This fix is not applicable if the application does not use session cookies with websocket connections.\n\nOption C — Workaround\nand it is working so far. I haven't done extensive testing.\nWhen NOT to use: This fix is not applicable if the application does not use session cookies with websocket connections.\n\n

Why This Fix Works in Production

  • Trigger: asgi = self.app(self.scope)
  • Mechanism: The session middleware incorrectly processes websocket connections as HTTP requests
  • Why the fix works: Resolves the issue by changing the session middleware to use HTTPConnection instead of Request, allowing proper handling of websocket connections. (first fixed release: 0.13.4).
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

  • Shows up under Python 3.7 in real deployments (not just unit tests).
  • The session middleware incorrectly processes websocket connections as HTTP requests
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

  • GitHub issue: #483
  • Fix PR: https://github.com/kludex/starlette/pull/597
  • First fixed release: 0.13.4
  • 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.29

Discussion

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

“Can reproduce on Starlette 0.11.1. Is there any known workaround?”
@Taarek · 2019-05-18 · source
“Thanks folks. Can anyone confirm on the 0.12 prerelease?”
@lovelydinosaur · 2019-05-20 · source
“Ah yeah I think it's still an issue in master. Looks like this: https://github.com/encode/starlette/blob/master/starlette/middleware/sessions.py#L36 ought to be Connection not Request.”
@lovelydinosaur · 2019-05-20 · source
“Is there any progression on this issue ? I am currently evaluating frameworks (for a hobby project), and I would like to use Starlette API,…”
@TheBlusky · 2019-06-07 · source

Failure Signature (Search String)

  • asgi = self.app(self.scope)

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File ".venv/lib/python3.7/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 146, in run_asgi asgi = self.app(self.scope) File ".venv/lib/python3.7/site-packages/starlette/applications.py", line 134, in __call__ return self.error_middleware(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/errors.py", line 88, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 37, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/base.py", line 22, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/base.py", line 22, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/exceptions.py", line 49, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/routing.py", line 587, in __call__ return route(scope) File ".venv/lib/python3.7/site-packages/starlette/routing.py", line 356, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/applications.py", line 134, in __call__ return self.error_middleware(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/errors.py", line 88, in __call__ return self.app(scope ... (truncated) ...

Minimal Reproduction

repro.py
Traceback (most recent call last): File ".venv/lib/python3.7/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 146, in run_asgi asgi = self.app(self.scope) File ".venv/lib/python3.7/site-packages/starlette/applications.py", line 134, in __call__ return self.error_middleware(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/errors.py", line 88, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 37, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/base.py", line 22, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/base.py", line 22, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/exceptions.py", line 49, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/routing.py", line 587, in __call__ return route(scope) File ".venv/lib/python3.7/site-packages/starlette/routing.py", line 356, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/applications.py", line 134, in __call__ return self.error_middleware(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/errors.py", line 88, in __call__ return self.app(scope) File ".venv/lib/python3.7/site-packages/starlette/middleware/sessions.py", line 34, in __call__ request = Request(scope) File ".venv/lib/python3.7/site-packages/starlette/requests.py", line 128, in __init__ assert scope["type"] == "http"

Environment

  • Python: 3.7

What Broke

Websocket connections fail with assertion errors when session cookies are enabled.

Why It Broke

The session middleware incorrectly processes websocket connections as HTTP requests

Fix Options (Details)

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

Upgrade to version 0.13.4 or later.

When NOT to use: This fix is not applicable if the application does not use session cookies with websocket connections.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Option C — Workaround Temporary workaround

and it is working so far. I haven't done extensive testing.

When NOT to use: This fix is not applicable if the application does not use session cookies with websocket connections.

Use only if you cannot change versions today. Treat this as a stopgap and remove once upgraded.

Fix reference: https://github.com/kludex/starlette/pull/597

First fixed release: 0.13.4

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

  • This fix is not applicable if the application does not use session cookies with websocket connections.

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 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.13.4 Fixed

Related Issues

No related fixes found.

Sources

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