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.
Description
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.
Quand vous le voyez
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.
Comment résoudre
Review the server's documented policies and constraints. Check for rate limiting, authentication token expiry, or forbidden message content that triggered the rejection.
Description
The server is terminating the connection because it is restarting. The client should reconnect after a brief delay.
Quand vous le voyez
The server is performing a planned restart — for example, during a deployment or configuration reload. The connection will be available again shortly.
Comment résoudre
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.
Différences clés
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.
WebSocket 1012: The server is terminating the connection because it is restarting. The client should reconnect after a brief delay.
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.
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.
Quand utiliser lequel
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.