1006
communication
connection_error
ai_generated
partial
WebSocket收到状态码为1006的关闭帧(异常关闭)
WebSocket close frame received with status code 1006 (abnormal closure)
ID: communication/websocket-1006-abnormal-closure
70%修复率
82%置信度
1证据数
2024-01-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| RFC 6455 | active | — | — | — |
| WebSocket++ 0.8.2 | active | — | — | — |
| ws 8.16 | active | — | — | — |
| Node.js 20 | active | — | — | — |
根因分析
WebSocket连接在没有关闭帧的情况下意外终止,通常由网络故障、代理超时或服务器崩溃引起。
English
WebSocket connection terminated unexpectedly without a close frame, typically due to network failure, proxy timeout, or server crash.
官方文档
https://datatracker.ietf.org/doc/html/rfc6455#section-7.4.1解决方案
-
Implement automatic reconnection with exponential backoff on the client. When a 1006 closure is detected, wait 1s, 2s, 4s, etc., before reconnecting. Log the event to diagnose network stability.
-
Check proxy and load balancer settings for WebSocket timeout. On NGINX, ensure proxy_read_timeout is set high (e.g., 3600s) and proxy_http_version is 1.1 with Connection upgrade.
无效尝试
常见但无效的做法:
-
Increase the WebSocket ping/pong interval on the client
70% 失败
1006 is not a timeout error; it's an abnormal closure where no close frame is sent. Ping/pong intervals only help with idle timeouts, not sudden disconnections
-
Disable SSL/TLS on the WebSocket connection
85% 失败
1006 can occur over both ws:// and wss://; disabling encryption does not prevent network-level drops
-
Switch from WebSocket to long polling as a workaround
90% 失败
Long polling introduces different failure modes and does not fix the root cause of unstable WebSocket connections