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.

描述

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.

描述

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

何时出现

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.

如何修复

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.

主要区别

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.

何时使用哪个

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.

了解更多