WebSocket frame exceeds maximum size: 65535 bytes
ID: communication/websocket-message-too-large-fragmentation
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Node.js ws 8.13.0 | active | — | — | — |
| Python websockets 12.0 | active | — | — | — |
| Go gorilla/websocket 1.5.1 | active | — | — | — |
| Java Tyrus 2.0.0 | active | — | — | — |
| Nginx 1.25.0 | active | — | — | — |
Root Cause
A WebSocket frame payload exceeds the 16-bit length limit (65535 bytes) when the application sends data without enabling fragmentation or using extension frames, violating RFC 6455 section 5.2.
generic中文
WebSocket帧的有效载荷超过16位长度限制(65535字节),原因是应用程序在未启用分片或使用扩展帧的情况下发送数据,违反了RFC 6455第5.2节。
Official Documentation
https://datatracker.ietf.org/doc/html/rfc6455#section-5.2Workarounds
-
90% success Enable WebSocket fragmentation in the sender: for Python websockets, use 'await websocket.send(message, fragment_size=16384)' to automatically split large messages into multiple frames.
Enable WebSocket fragmentation in the sender: for Python websockets, use 'await websocket.send(message, fragment_size=16384)' to automatically split large messages into multiple frames.
-
85% success Implement application-level chunking: split the payload into chunks of < 65535 bytes on the client and reassemble on the server using a sequence ID.
Implement application-level chunking: split the payload into chunks of < 65535 bytes on the client and reassemble on the server using a sequence ID.
-
75% success Use WebSocket extensions like 'permessage-deflate' to compress data, reducing payload size below the limit.
Use WebSocket extensions like 'permessage-deflate' to compress data, reducing payload size below the limit.
中文步骤
Enable WebSocket fragmentation in the sender: for Python websockets, use 'await websocket.send(message, fragment_size=16384)' to automatically split large messages into multiple frames.
Implement application-level chunking: split the payload into chunks of < 65535 bytes on the client and reassemble on the server using a sequence ID.
Use WebSocket extensions like 'permessage-deflate' to compress data, reducing payload size below the limit.
Dead Ends
Common approaches that don't work:
-
Increase the frame size limit in the WebSocket library configuration
85% fail
The RFC mandates a maximum frame payload of 2^16-1 bytes for unfragmented frames; increasing the limit may cause protocol-level errors or disconnection.
-
Switch to HTTP/2 streaming instead of WebSocket
90% fail
HTTP/2 streaming has different semantics and may not support bidirectional real-time communication; it requires significant application redesign.
-
Compress the data before sending to reduce payload size
70% fail
Compression may not be feasible for binary data or real-time streams, and it adds CPU overhead; it also doesn't address the root cause of not using fragmentation.