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.
الفروق الرئيسية
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.
WebSocket 1010: The client is terminating the connection because the server did not negotiate one or more expected extensions in the handshake response.
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.
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.