WebSocket

WebSocket 1006 Abnormal Closure vs 1010 Mandatory Extension

Both WebSocket 1006 (Abnormal Closure) and 1010 (Mandatory Extension) belong to the WebSocket Close Codes category. 1006 indicates 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. Meanwhile, 1010 means that the client is terminating the connection because the server did not negotiate one or more expected extensions in the handshake response.

Descripción

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

Cuándo lo verás

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.

Cómo solucionarlo

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.

Descripción

The client is terminating the connection because the server did not negotiate one or more expected extensions in the handshake response.

Cuándo lo verás

The client requested a required WebSocket extension (e.g., permessage-deflate compression) during the handshake, but the server did not include it in its response.

Cómo solucionarlo

Enable the required extension on the server, or update the client to make the extension optional. Check the Sec-WebSocket-Extensions header in the handshake response.

Diferencias clave

1.

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.

2.

WebSocket 1010: The client is terminating the connection because the server did not negotiate one or more expected extensions in the handshake response.

3.

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.

4.

You encounter 1010 when the client requested a required WebSocket extension (e.g., permessage-deflate compression) during the handshake, but the server did not include it in its response.

Cuándo usar cada uno

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. For 1010 (Mandatory Extension): Enable the required extension on the server, or update the client to make the extension optional. Check the Sec-WebSocket-Extensions header in the handshake response.

Saber más