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.

Description

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

When You See It

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

How to Fix

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.

Description

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

When You See It

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

How to Fix

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.

Key Differences

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.

When to Use Which

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.

Learn More