# WebSocket 帧超过最大大小：接收 1048576 字节，最大允许 65536 字节（错误代码 1009）

- **ID:** `communication/websocket-1009-message-too-big`
- **领域:** communication
- **类别:** protocol_error
- **错误码:** `1009`
- **验证级别:** ai_generated
- **修复率:** 84%

## 根因

WebSocket 服务器或客户端以代码 1009 关闭连接，因为接收的消息负载超过配置的最大帧大小，通常是由于未分割的大负载或配置错误的限制。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| RFC 6455 | active | — | — |
| Node.js ws library 8.12.0 | active | — | — |
| Python websockets 12.0 | active | — | — |
| Go gorilla/websocket 1.5.0 | active | — | — |

## 解决方案

1. ```
   Implement message splitting on the sender: break large payloads (e.g., > 64KB) into multiple WebSocket messages with a sequence identifier, then reassemble on the receiver. This avoids exceeding the frame limit.
   ```
2. ```
   Increase the server's max frame size (e.g., in Python websockets: set 'max_size' parameter to None or a larger value like 10MB).
   ```
3. ```
   Use compression (e.g., permessage-deflate extension) to reduce payload size below the limit, if both client and server support it.
   ```

## 无效尝试

- **** — Increasing the max frame size on the client only shifts the problem; the server may still enforce a smaller limit, causing asymmetric failures. (60% 失败率)
- **** — Disabling fragmentation entirely (e.g., setting 'permessage-deflate' off) doesn't reduce payload size and may not be supported by all libraries. (75% 失败率)
- **** — Switching to a different WebSocket library without adjusting limits often results in the same default cap (e.g., 65536 bytes in many implementations). (70% 失败率)
