The Fix
Upgrade to version 0.23.2 or later.
Based on closed Kludex/uvicorn issue #1927 · PR/commit linked
@@ -7,7 +7,7 @@ h11 @ git+https://github.com/python-hyper/h11.git@master
a2wsgi==1.7.0
wsproto==1.2.0
-websockets==10.4
+websockets==11.0.3
INFO: Uvicorn running on http://127.0.0.1:64969 (Press CTRL+C to quit)
INFO: ('127.0.0.1', 64970) - "WebSocket /" [accepted]
ERROR: ASGI callable should return None, but returned '123'.
INFO: connection open
ERROR: closing handshake failed
Traceback (most recent call last):
File "/Users/myk/dev/websockets/src/websockets/legacy/server.py", line 244, in handler
await self.close()
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 768, in close
await asyncio.wait_for(
File "/Users/myk/.pyenv/versions/3.11.2/lib/python3.11/asyncio/tasks.py", line 479, in wait_for
return fut.result()
^^^^^^^^^^^^
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 1241, in write_close_frame
await self.write_frame(True, OP_CLOSE, data, _state=State.CLOSING)
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 1214, in write_frame
await self.drain()
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 1203, in drain
await self.ensure_open()
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 944, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: sent 1000 (OK); no close frame received
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.23.2 or later.\nWhen NOT to use: Do not apply this fix if using a version of websockets prior to 11.0.\n\n
Why This Fix Works in Production
- Trigger: ERROR: ASGI callable should return None, but returned '123'.
- Mechanism: Bumps the websockets library to version 11.0.3 to address issues with the Uvicorn test suite.
- Why the fix works: Bumps the websockets library to version 11.0.3 to address issues with the Uvicorn test suite. (first fixed release: 0.23.2).
- If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).
Why This Breaks in Prod
- Shows up under Python 3.11 in real deployments (not just unit tests).
- Surfaces as: INFO: Uvicorn running on http://127.0.0.1:64969 (Press CTRL+C to quit)
Proof / Evidence
- GitHub issue: #1927
- Fix PR: https://github.com/kludex/uvicorn/pull/2061
- First fixed release: 0.23.2
- 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.25
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“I bisected the failure to: https://github.com/python-websockets/websockets/commit/5113cd3afe7cbf5f740d80db8449670c27c90101 This commit creates a subtle change in the timing of how connections are closed: it's happening faster in 11.0…”
“The docstring says: > The ASGI callable should return 'None'”
“> I looked at the ASGI spec but didn't find anything about the return value of the ASGI callable. It's just that we enforce the…”
“I bumped the log level and captured these logs of a failing test: We have the debug logs of the client but not of the…”
Failure Signature (Search String)
- ERROR: ASGI callable should return None, but returned '123'.
Error Message
Stack trace
Error Message
-------------
INFO: Uvicorn running on http://127.0.0.1:64969 (Press CTRL+C to quit)
INFO: ('127.0.0.1', 64970) - "WebSocket /" [accepted]
ERROR: ASGI callable should return None, but returned '123'.
INFO: connection open
ERROR: closing handshake failed
Traceback (most recent call last):
File "/Users/myk/dev/websockets/src/websockets/legacy/server.py", line 244, in handler
await self.close()
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 768, in close
await asyncio.wait_for(
File "/Users/myk/.pyenv/versions/3.11.2/lib/python3.11/asyncio/tasks.py", line 479, in wait_for
return fut.result()
^^^^^^^^^^^^
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 1241, in write_close_frame
await self.write_frame(True, OP_CLOSE, data, _state=State.CLOSING)
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 1214, in write_frame
await self.drain()
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 1203, in drain
await self.ensure_open()
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 944, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: sent 1000 (OK); no close frame received
Minimal Reproduction
INFO: Uvicorn running on http://127.0.0.1:64969 (Press CTRL+C to quit)
INFO: ('127.0.0.1', 64970) - "WebSocket /" [accepted]
ERROR: ASGI callable should return None, but returned '123'.
INFO: connection open
ERROR: closing handshake failed
Traceback (most recent call last):
File "/Users/myk/dev/websockets/src/websockets/legacy/server.py", line 244, in handler
await self.close()
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 768, in close
await asyncio.wait_for(
File "/Users/myk/.pyenv/versions/3.11.2/lib/python3.11/asyncio/tasks.py", line 479, in wait_for
return fut.result()
^^^^^^^^^^^^
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 1241, in write_close_frame
await self.write_frame(True, OP_CLOSE, data, _state=State.CLOSING)
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 1214, in write_frame
await self.drain()
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 1203, in drain
await self.ensure_open()
File "/Users/myk/dev/websockets/src/websockets/legacy/protocol.py", line 944, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: sent 1000 (OK); no close frame received
Environment
- Python: 3.11
What Broke
Uvicorn test suite fails due to unexpected connection closure behavior with websockets 11.0.
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.23.2 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/uvicorn/pull/2061
First fixed release: 0.23.2
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not apply this fix if using a version of websockets prior to 11.0.
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.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.23.2 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.