1009
communication
protocol_error
ai_generated
true
WebSocket 关闭帧收到状态码 1009(消息过大)
WebSocket close frame received with status code 1009 (message too large)
ID: communication/websocket-close-frame-1009-message-too-large
82%修复率
88%置信度
1证据数
2023-11-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| ws 8.16.0 | active | — | — | — |
| nginx 1.24.0 | active | — | — | — |
| AWS ALB 2.0 | active | — | — | — |
根因分析
WebSocket 消息负载超出服务器或代理允许的最大帧大小(默认 65535 字节)。
English
The WebSocket message payload exceeds the maximum allowed frame size (default 65535 bytes) on the server or proxy.
官方文档
https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent解决方案
-
Fragment the large message into smaller chunks on the client and reassemble on the server: In JavaScript, split payload into 32KB chunks and send each with a sequence number; on the server (Node.js), buffer chunks until all received.
-
Increase the server's max frame size: In nginx, set `proxy_read_timeout 300s;` and `proxy_buffers 8 32k;` but more importantly configure `proxy_http_version 1.1;` and ensure the WebSocket library (e.g., ws in Node.js) sets `maxPayload: 256 * 1024`.
-
Use a message queue (e.g., Redis Pub/Sub) to offload large payloads and send only references via WebSocket.
无效尝试
常见但无效的做法:
-
Increase the WebSocket frame size limit on the client side only
85% 失败
The limit is enforced by the server or intermediate proxy; client changes alone don't override it.
-
Compress the payload with gzip before sending
75% 失败
WebSocket frames are already binary-safe; compression must be negotiated via extensions (permessage-deflate) at connection setup.
-
Switch to long-polling with HTTP POST to avoid frame limits
65% 失败
Long-polling introduces latency and doesn't solve the underlying payload size issue; the same data may still hit HTTP body limits.