WebSocket

WebSocket 1008 Policy Violation vs 1012 Service Restart

Both WebSocket 1008 (Policy Violation) and 1012 (Service Restart) belong to the WebSocket Close Codes category. 1008 indicates that an endpoint is terminating the connection because it received a message that violates its policy. This is a generic code when none of the other codes (1003, 1009) are suitable. Meanwhile, 1012 means that the server is terminating the connection because it is restarting. The client should reconnect after a brief delay.

Beschreibung

An endpoint is terminating the connection because it received a message that violates its policy. This is a generic code when none of the other codes (1003, 1009) are suitable.

Wann Sie es sehen

The server rejected a message because it violated an application-level policy — for example, sending messages too rapidly, exceeding rate limits, or failing authentication after the handshake.

Wie man es behebt

Review the server's documented policies and constraints. Check for rate limiting, authentication token expiry, or forbidden message content that triggered the rejection.

Beschreibung

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

Wann Sie es sehen

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

Wie man es behebt

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.

Wesentliche Unterschiede

1.

WebSocket 1008: An endpoint is terminating the connection because it received a message that violates its policy. This is a generic code when none of the other codes (1003, 1009) are suitable.

2.

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

3.

You encounter 1008 when the server rejected a message because it violated an application-level policy — for example, sending messages too rapidly, exceeding rate limits, or failing authentication after the handshake.

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.

Wann welchen verwenden

For 1008 (Policy Violation): Review the server's documented policies and constraints. Check for rate limiting, authentication token expiry, or forbidden message content that triggered the rejection. 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.

Mehr erfahren