WebSocket

WebSocket 1011 Internal Error vs 1012 Service Restart

Both WebSocket 1011 (Internal Error) and 1012 (Service Restart) belong to the WebSocket Close Codes category. 1011 indicates that the server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request. Meanwhile, 1012 means that the server is terminating the connection because it is restarting. The client should reconnect after a brief delay.

Descrição

The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

Quando você o vê

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

Como corrigir

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.

Descrição

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

Quando você o vê

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

Como corrigir

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.

Diferenças principais

1.

WebSocket 1011: The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

2.

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

3.

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.

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.

Quando usar qual

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

Saiba mais