1006
api
network_error
ai_generated
partial
WebSocket 关闭代码 1006:异常关闭
WebSocket close code 1006: Abnormal Closure
ID: api/websocket-close-code-1006-abnormal-closure
70%修复率
85%置信度
1证据数
2023-11-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| WebSocket RFC 6455 | active | — | — | — |
| ws library v8.16 | active | — | — | — |
| Node.js v20 | active | — | — | — |
根因分析
WebSocket 连接在未发送正常关闭帧的情况下意外关闭,通常由于网络问题、代理超时或服务器崩溃。
English
The WebSocket connection was closed unexpectedly without a normal close frame, often due to network issues, proxy timeouts, or server crash.
官方文档
https://datatracker.ietf.org/doc/html/rfc6455#section-7.4.1解决方案
-
Implement exponential backoff reconnection with jitter.
-
Add a health check endpoint and only reconnect if server is alive.
无效尝试
常见但无效的做法:
-
70% 失败
Reconnecting without delay may hit the same network issue or server load, causing repeated 1006 closures.
-
80% 失败
The error is often network-related, not a code logic bug; rewriting may not address the root cause.
-
50% 失败
The library is rarely the cause; the underlying TCP connection is the issue.