WebSocket

WebSocket 1001 Going Away vs 1012 Service Restart

Both WebSocket 1001 (Going Away) and 1012 (Service Restart) 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, 1012 means that the server is terminating the connection because it is restarting. The client should reconnect after a brief delay.

Mô tả

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

Khi bạn thấy mã này

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.

Cách khắc phục

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

Mô tả

The server is terminating the connection because it is restarting. The client should reconnect after a brief delay.

Khi bạn thấy mã này

The server is performing a planned restart — for example, during a deployment or configuration reload. The connection will be available again shortly.

Cách khắc phục

Implement automatic reconnection with a short delay (1-5 seconds). This code signals that reconnecting is expected and should succeed once the server is back up.

Sự khác biệt chính

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 1012: The server is terminating the connection because it is restarting. The client should reconnect after a brief delay.

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 1012 when the server is performing a planned restart — for example, during a deployment or configuration reload. The connection will be available again shortly.

Khi nào dùng cái nào

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 1012 (Service Restart): Implement automatic reconnection with a short delay (1-5 seconds). This code signals that reconnecting is expected and should succeed once the server is back up.

Tìm hiểu thêm