WebSocket

WebSocket 1000 Normal Closure vs 1010 Mandatory Extension

Both WebSocket 1000 (Normal Closure) and 1010 (Mandatory Extension) belong to the WebSocket Close Codes category. 1000 indicates that the connection has been closed cleanly, meaning the purpose for which it was established has been fulfilled. Both endpoints agree the session is complete. 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.

Описание

The connection has been closed cleanly, meaning the purpose for which it was established has been fulfilled. Both endpoints agree the session is complete.

Когда вы это видите

The WebSocket connection closed gracefully after both sides finished exchanging data. This is the expected close code for a successful session.

Как исправить

No fix needed — this indicates everything worked as intended. If you did not expect the connection to close, check your application logic for premature close() calls.

Описание

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 1000: The connection has been closed cleanly, meaning the purpose for which it was established has been fulfilled. Both endpoints agree the session is complete.

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 1000 when the WebSocket connection closed gracefully after both sides finished exchanging data. This is the expected close code for a successful session.

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 1000 (Normal Closure): No fix needed — this indicates everything worked as intended. If you did not expect the connection to close, check your application logic for premature close() calls. 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.

Узнать больше