WebSocket

WebSocket 1001 Going Away vs 1011 Internal Error

Both WebSocket 1001 (Going Away) and 1011 (Internal Error) 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, 1011 means that the server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

説明

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 server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

このコードが表示される場合

The server hit an unhandled exception or crashed while processing a WebSocket message. This is the WebSocket equivalent of HTTP 500 Internal Server Error.

解決方法

Check the server-side application logs for stack traces and exceptions. Fix the underlying bug that caused the crash and add proper error handling around message processing.

主な違い

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 1011: The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

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 1011 when the server hit an unhandled exception or crashed while processing a WebSocket message. This is the WebSocket equivalent of HTTP 500 Internal Server Error.

どちらをいつ使うか

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 1011 (Internal Error): Check the server-side application logs for stack traces and exceptions. Fix the underlying bug that caused the crash and add proper error handling around message processing.

詳しく見る