Jump to solution
Verify

The Fix

Upgrade to version 0.14.0 or later.

Based on closed Kludex/uvicorn issue #868 · PR/commit linked

Production note: Watch p95/p99 latency and retry volume; timeouts can turn into retry storms and duplicate side-effects.

Jump to Verify Open PR/Commit
@@ -1,7 +1,7 @@ # Explicit optionals -wsproto==0.15.* +wsproto==1.0.*
repro.py
[ 48s] _________________ test_supported_upgrade_request[H11Protocol] __________________ [ 48s] [ 48s] protocol_cls = <class 'uvicorn.protocols.http.h11_impl.H11Protocol'> [ 48s] [ 48s] @pytest.mark.parametrize("protocol_cls", HTTP_PROTOCOLS) [ 48s] def test_supported_upgrade_request(protocol_cls): [ 48s] app = Response("Hello, world", media_type="text/plain") [ 48s] [ 48s] protocol = get_connected_protocol(app, protocol_cls, ws="wsproto") [ 48s] protocol.data_received(UPGRADE_REQUEST) [ 48s] [ 48s] > assert b"HTTP/1.1 426 " in protocol.transport.buffer [ 48s] E AssertionError: assert b'HTTP/1.1 426 ' in b'HTTP/1.1 400 \r\nSec-WebSocket-Version: 13\r\ncontent-length: 0\r\n\r\n' [ 48s] E + where b'HTTP/1.1 400 \r\nSec-WebSocket-Version: 13\r\ncontent-length: 0\r\n\r\n' = <test_http.MockTransport object at 0x7f62c2f8b820>.buffer [ 48s] E + where <test_http.MockTransport object at 0x7f62c2f8b820> = <uvicorn.protocols.http.h11_impl.H11Protocol object at 0x7f62c2f8b0a0>.transport [ 48s] [ 48s] tests/protocols/test_http.py:676: AssertionError [ 48s] ______________ test_supported_upgrade_request[HttpToolsProtocol] _______________ [ 48s] [ 48s] protocol_cls = <class 'uvicorn.protocols.http.httptools_impl.HttpToolsProtocol'> [ 48s] [ 48s] @pytest.mark.parametrize("protocol_cls", HTTP_PROTOCOLS) [ 48s] def test_supported_upgrade_request(protocol_cls): [ 48s] app = Response("Hello, world", media_type="text/plain") [ 48s] [ 48s] protocol = get_connected_protocol(app, protocol_cls, ws="wsproto") [ 48s] protocol.data_received(UPGRADE_REQUEST) [ 48s] [ 48s] > assert b"HTTP/1.1 426 " in protocol.transport.buffer [ 48s] E AssertionError: assert b'HTTP/1.1 426 ' in b'HTTP/1.1 400 \r\nSec-WebSocket-Version: 13\r\ncontent-length: 0\r\n\r\n' [ 48s] E + where b'HTTP/1.1 400 \r\nSec-WebSocket-Version: 13\r\ncontent-length: 0\r\n\r\n' = <test_http.MockTransport object at 0x7f62c2fbbfa0>.buffer [ 48s] E + where <test_http.MockTransport object at 0x7f62c2fbbfa0> = <uvicorn.protocols.http.httptools_impl.HttpToolsProtocol object at 0x7f62c07566d0>.transport [ 48s] [ 48s] tests/protocols/test_http.py:676: AssertionError [ 48s] _______________________ test_invalid_upgrade[WSProtocol] _______________________ [ 48s] [ 49s] protocol_cls = <class 'uvicorn.protocols.websockets.wsproto_impl.WSProtocol'> [ 49s] [ 49s] @pytest.mark.parametrize("protocol_cls", WS_PROTOCOLS) [ 49s] def test_invalid_upgrade(protocol_cls): [ 49s] def app(scope): [ 49s] return None [ 49s] [ 49s] with run_server(app, protocol_cls=protocol_cls) as url: [ 49s] url = url.replace("ws://", "http://") [ 49s] response = requests.get( [ 49s] url, headers={"upgrade": "websocket", "connection": "upgrade"}, timeout=5 [ 49s] ) [ 49s] if response.status_code == 426: [ 49s] # response.text == "" [ 49s] pass # ok, wsproto 0.13 [ 49s] else: [ 49s] assert response.status_code == 400 [ 49s] > assert response.text.lower().strip().rstrip(".") in [ [ 49s] "missing sec-websocket-key header", [ 49s] "missing sec-websocket-version header", # websockets [ 49s] "missing or empty sec-websocket-key header", # wsproto [ 49s ... (truncated) ...
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.14.0 or later.\nWhen NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.\n\n

Why This Fix Works in Production

  • Trigger: AssertionError: assert b'HTTP/1.1 426 ' in b'HTTP/1.1 400 \r Sec-WebSocket-Version: 13\r content-length: 0\r \r '
  • Mechanism: The wsproto version was outdated, causing test failures related to WebSocket upgrades
  • Why the fix works: Updated wsproto to 1.0.0 to resolve test failures related to WebSocket upgrades. (first fixed release: 0.14.0).
Production impact:
  • If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).

Why This Breaks in Prod

  • Triggered by an upgrade/regression window: 0.3.8–84.87 breaks; 0.14.0 is the first fixed release.
  • Shows up under Python 3.8.6 in real deployments (not just unit tests).
  • The wsproto version was outdated, causing test failures related to WebSocket upgrades
  • Surfaces as: AssertionError: assert b'HTTP/1.1 426 ' in b'HTTP/1.1 400 \r\nSec-WebSocket-Version: 13\r\ncontent-length: 0\r\n\r\n'

Proof / Evidence

  • GitHub issue: #868
  • Fix PR: https://github.com/kludex/uvicorn/pull/892
  • First fixed release: 0.14.0
  • Affected versions: 0.3.8–84.87
  • 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).

“One possible cause is the RPM builds are using a de-vendored httptools, which uses https://github.com/nodejs/http-parser v2.9.4, while the tests here are using https://github.com/MagicStack/httptools/tree/master/vendor v2.9.0”
@jayvdb · 2020-11-29 · confirmation · source
“we pin wsproto at 0.15.* I think so that might explain why our test didnt see that.”
@euri10 · 2020-12-09 · source

Failure Signature (Search String)

  • AssertionError: assert b'HTTP/1.1 426 ' in b'HTTP/1.1 400 \r\nSec-WebSocket-Version: 13\r\ncontent-length: 0\r\n\r\n'

Error Message

Stack trace
error.txt
Error Message ------------- AssertionError: assert b'HTTP/1.1 426 ' in b'HTTP/1.1 400 \r\nSec-WebSocket-Version: 13\r\ncontent-length: 0\r\n\r\n'

Minimal Reproduction

repro.py
[ 48s] _________________ test_supported_upgrade_request[H11Protocol] __________________ [ 48s] [ 48s] protocol_cls = <class 'uvicorn.protocols.http.h11_impl.H11Protocol'> [ 48s] [ 48s] @pytest.mark.parametrize("protocol_cls", HTTP_PROTOCOLS) [ 48s] def test_supported_upgrade_request(protocol_cls): [ 48s] app = Response("Hello, world", media_type="text/plain") [ 48s] [ 48s] protocol = get_connected_protocol(app, protocol_cls, ws="wsproto") [ 48s] protocol.data_received(UPGRADE_REQUEST) [ 48s] [ 48s] > assert b"HTTP/1.1 426 " in protocol.transport.buffer [ 48s] E AssertionError: assert b'HTTP/1.1 426 ' in b'HTTP/1.1 400 \r\nSec-WebSocket-Version: 13\r\ncontent-length: 0\r\n\r\n' [ 48s] E + where b'HTTP/1.1 400 \r\nSec-WebSocket-Version: 13\r\ncontent-length: 0\r\n\r\n' = <test_http.MockTransport object at 0x7f62c2f8b820>.buffer [ 48s] E + where <test_http.MockTransport object at 0x7f62c2f8b820> = <uvicorn.protocols.http.h11_impl.H11Protocol object at 0x7f62c2f8b0a0>.transport [ 48s] [ 48s] tests/protocols/test_http.py:676: AssertionError [ 48s] ______________ test_supported_upgrade_request[HttpToolsProtocol] _______________ [ 48s] [ 48s] protocol_cls = <class 'uvicorn.protocols.http.httptools_impl.HttpToolsProtocol'> [ 48s] [ 48s] @pytest.mark.parametrize("protocol_cls", HTTP_PROTOCOLS) [ 48s] def test_supported_upgrade_request(protocol_cls): [ 48s] app = Response("Hello, world", media_type="text/plain") [ 48s] [ 48s] protocol = get_connected_protocol(app, protocol_cls, ws="wsproto") [ 48s] protocol.data_received(UPGRADE_REQUEST) [ 48s] [ 48s] > assert b"HTTP/1.1 426 " in protocol.transport.buffer [ 48s] E AssertionError: assert b'HTTP/1.1 426 ' in b'HTTP/1.1 400 \r\nSec-WebSocket-Version: 13\r\ncontent-length: 0\r\n\r\n' [ 48s] E + where b'HTTP/1.1 400 \r\nSec-WebSocket-Version: 13\r\ncontent-length: 0\r\n\r\n' = <test_http.MockTransport object at 0x7f62c2fbbfa0>.buffer [ 48s] E + where <test_http.MockTransport object at 0x7f62c2fbbfa0> = <uvicorn.protocols.http.httptools_impl.HttpToolsProtocol object at 0x7f62c07566d0>.transport [ 48s] [ 48s] tests/protocols/test_http.py:676: AssertionError [ 48s] _______________________ test_invalid_upgrade[WSProtocol] _______________________ [ 48s] [ 49s] protocol_cls = <class 'uvicorn.protocols.websockets.wsproto_impl.WSProtocol'> [ 49s] [ 49s] @pytest.mark.parametrize("protocol_cls", WS_PROTOCOLS) [ 49s] def test_invalid_upgrade(protocol_cls): [ 49s] def app(scope): [ 49s] return None [ 49s] [ 49s] with run_server(app, protocol_cls=protocol_cls) as url: [ 49s] url = url.replace("ws://", "http://") [ 49s] response = requests.get( [ 49s] url, headers={"upgrade": "websocket", "connection": "upgrade"}, timeout=5 [ 49s] ) [ 49s] if response.status_code == 426: [ 49s] # response.text == "" [ 49s] pass # ok, wsproto 0.13 [ 49s] else: [ 49s] assert response.status_code == 400 [ 49s] > assert response.text.lower().strip().rstrip(".") in [ [ 49s] "missing sec-websocket-key header", [ 49s] "missing sec-websocket-version header", # websockets [ 49s] "missing or empty sec-websocket-key header", # wsproto [ 49s ... (truncated) ...

Environment

  • Python: 3.8.6

What Broke

Tests were failing on openSUSE rpm VMs, leading to potential deployment issues.

Why It Broke

The wsproto version was outdated, causing test failures related to WebSocket upgrades

Fix Options (Details)

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

Upgrade to version 0.14.0 or later.

When NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.

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

Option D — Guard side-effects with OnceOnly Guardrail for side-effects

Mitigate duplicate external side-effects under retries/timeouts/agent loops by gating the operation before calling external systems.

  • Place OnceOnly between your code/agent and real side-effects (Stripe, emails, CRM, APIs).
  • Use a stable key per side-effect (e.g., customer_id + action + idempotency_key).
  • Fail-safe: configure fail-open vs fail-closed based on blast radius and spend risk.
  • This does NOT fix data corruption; it only prevents duplicate side-effects.
Show example snippet (optional)
onceonly.py
from onceonly import OnceOnly import os once = OnceOnly(api_key=os.environ["ONCEONLY_API_KEY"], fail_open=True) # Stable idempotency key per real side-effect. # Use a request id / job id / webhook delivery id / Stripe event id, etc. event_id = "evt_..." # replace key = f"stripe:webhook:{event_id}" res = once.check_lock(key=key, ttl=3600) if res.duplicate: return {"status": "already_processed"} # Safe to execute the side-effect exactly once. handle_event(event_id)

See OnceOnly SDK

When NOT to use: Do not use this to hide logic bugs or data corruption. Use it to block duplicate external side-effects and enforce tool permissions/spend caps.

Fix reference: https://github.com/kludex/uvicorn/pull/892

First fixed release: 0.14.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 if it changes public behavior or if the failure cannot be reproduced.
  • Do not use this to hide logic bugs or data corruption. Use it to block duplicate external side-effects and enforce tool permissions/spend caps.

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.
  • Make timeouts explicit and test them (unit + integration) to avoid silent behavior changes.
  • Instrument retries (attempt count + reason) and alert on spikes to catch dependency slowdowns.

Version Compatibility Table

VersionStatus
0.3.8 Broken
10.2.1 Broken
84.87 Broken
0.14.0 Fixed

Related Issues

No related fixes found.

Sources

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