WebSocket

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.

Description

An endpoint is going away, such as a server shutting down or a browser navigating away from the page. The connection must be closed.

When You See It

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.

How to Fix

Implement automatic reconnection logic with exponential backoff in your client. If the server is restarting, the client should retry after a short delay.

Description

A reserved value indicating the connection was closed abnormally without a Close frame being sent. This code must not be set by an endpoint.

When You See It

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.

How to Fix

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.

Key Differences

1.

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.

2.

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.

3.

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.

4.

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.

When to Use Which

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.

Learn More