WebSocket 1001 Going Away vs 1006 Abnormal Closure
Both WebSocket 1001 (Going Away) and 1006 (Abnormal Closure) belong to the WebSocket Close Codes category. 1001 indicates that an endpoint is going away, such as a server shutting down or a browser navigating away from the page. The connection must be closed. Meanwhile, 1006 means that a reserved value indicating the connection was closed abnormally without a Close frame being sent. This code must not be set by an endpoint.
説明
An endpoint is going away, such as a server shutting down or a browser navigating away from the page. The connection must be closed.
このコードが表示される場合
The server is shutting down for maintenance, or the user navigated away from the page or closed the browser tab while a WebSocket was open.
解決方法
Implement automatic reconnection logic with exponential backoff in your client. If the server is restarting, the client should retry after a short delay.
説明
A reserved value indicating the connection was closed abnormally without a Close frame being sent. This code must not be set by an endpoint.
このコードが表示される場合
The TCP connection dropped unexpectedly — the server crashed, the network cable was unplugged, or a firewall killed the idle connection. No proper WebSocket Close handshake occurred.
解決方法
Implement reconnection with exponential backoff. Use WebSocket ping/pong frames to detect dead connections early. Check for network-level timeouts or aggressive load balancer idle limits.
主な違い
WebSocket 1001: An endpoint is going away, such as a server shutting down or a browser navigating away from the page. The connection must be closed.
WebSocket 1006: A reserved value indicating the connection was closed abnormally without a Close frame being sent. This code must not be set by an endpoint.
You encounter 1001 when the server is shutting down for maintenance, or the user navigated away from the page or closed the browser tab while a WebSocket was open.
You encounter 1006 when the TCP connection dropped unexpectedly — the server crashed, the network cable was unplugged, or a firewall killed the idle connection. No proper WebSocket Close handshake occurred.
どちらをいつ使うか
For 1001 (Going Away): Implement automatic reconnection logic with exponential backoff in your client. If the server is restarting, the client should retry after a short delay. For 1006 (Abnormal Closure): Implement reconnection with exponential backoff. Use WebSocket ping/pong frames to detect dead connections early. Check for network-level timeouts or aggressive load balancer idle limits.