WebSocket

WebSocket 1001 Going Away vs 1010 Mandatory Extension

Both WebSocket 1001 (Going Away) and 1010 (Mandatory Extension) 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, 1010 means that the client is terminating the connection because the server did not negotiate one or more expected extensions in the handshake response.

Описание

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

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

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.

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

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

Описание

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 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 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 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 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 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 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.

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