Jump to solution
Verify

The Fix

Fix WebSocket reader with fragmented masked messages to handle large payloads correctly.

Based on closed aio-libs/aiohttp issue #10763 · PR/commit linked

Jump to Verify Open PR/Commit
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@ +Fixed reading fragmented WebSocket messages when the payload was masked -- by :user:`bdraco`. + +The problem first appeared in 3.11.17
repro.py
from aiohttp import web async def Handler(request: web.Request): try: ws = web.WebSocketResponse(max_msg_size=100*1024*1024) await ws.prepare(request) while True: rawMsg = await ws.receive_bytes() print(len(rawMsg)) await ws.send_bytes(rawMsg) except BaseException as e: print(e) if __name__ == "__main__": app = web.Application() app.add_routes([web.get("/get_task", Handler)]) web.run_app(app, path="./test_websocket.socket", handle_signals=False)
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Apply the official fix\nFix WebSocket reader with fragmented masked messages to handle large payloads correctly.\nWhen NOT to use: This fix should not be applied if the application relies on the previous behavior of message handling.\n\n

Why This Fix Works in Production

  • Trigger: ```python-traceback
  • Mechanism: The issue was caused by a refactoring oversight in handling fragmented masked WebSocket messages
Production impact:
  • If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).

Why This Breaks in Prod

  • The issue was caused by a refactoring oversight in handling fragmented masked WebSocket messages
  • Production symptom (often without a traceback): ```python-traceback

Proof / Evidence

Discussion

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

“Version 3.11.18, which includes the fix, is currently being published. This update addresses the regression. Thank you for your patience and understanding.”
@bdraco · 2025-04-21 · source
“Thanks for the report. I'll take a look in the morning when I get up”
@bdraco · 2025-04-21 · source
“confirmed the reproducer. yanked 3.11.17 Will fix it in the morning. I have a good idea whats wrong”
@bdraco · 2025-04-21 · source
“On the bright side, I’ve identified the issue. Unfortunately, it stemmed from a straightforward refactoring oversight that I should have caught earlier.”
@bdraco · 2025-04-21 · source

Failure Signature (Search String)

  • ```python-traceback
  • No exception, but error message.
Copy-friendly signature
signature.txt
Failure Signature ----------------- ```python-traceback No exception, but error message.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- ```python-traceback No exception, but error message.

Minimal Reproduction

repro.py
from aiohttp import web async def Handler(request: web.Request): try: ws = web.WebSocketResponse(max_msg_size=100*1024*1024) await ws.prepare(request) while True: rawMsg = await ws.receive_bytes() print(len(rawMsg)) await ws.send_bytes(rawMsg) except BaseException as e: print(e) if __name__ == "__main__": app = web.Application() app.add_routes([web.get("/get_task", Handler)]) web.run_app(app, path="./test_websocket.socket", handle_signals=False)

What Broke

Clients sending large messages receive zero-length responses from the server.

Why It Broke

The issue was caused by a refactoring oversight in handling fragmented masked WebSocket messages

Fix Options (Details)

Option A — Apply the official fix

Fix WebSocket reader with fragmented masked messages to handle large payloads correctly.

When NOT to use: This fix should not be applied if the application relies on the previous behavior of message handling.

Fix reference: https://github.com/aio-libs/aiohttp/pull/10764

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 should not be applied if the application relies on the previous behavior of message handling.

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.

Related Issues

No related fixes found.

Sources

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