# WebSocket 关闭代码 1006：异常关闭

- **ID:** `api/websocket-close-code-1006-abnormal-closure`
- **领域:** api
- **类别:** network_error
- **错误码:** `1006`
- **验证级别:** ai_generated
- **修复率:** 70%

## 根因

WebSocket 连接在未发送正常关闭帧的情况下意外关闭，通常由于网络问题、代理超时或服务器崩溃。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| WebSocket RFC 6455 | active | — | — |
| ws library v8.16 | active | — | — |
| Node.js v20 | active | — | — |

## 解决方案

1. ```
   Implement exponential backoff reconnection with jitter.
   ```
2. ```
   Add a health check endpoint and only reconnect if server is alive.
   ```

## 无效尝试

- **** — Reconnecting without delay may hit the same network issue or server load, causing repeated 1006 closures. (70% 失败率)
- **** — The error is often network-related, not a code logic bug; rewriting may not address the root cause. (80% 失败率)
- **** — The library is rarely the cause; the underlying TCP connection is the issue. (50% 失败率)
