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.

説明

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.

このコードが表示される場合

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.

解決方法

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

説明

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

このコードが表示される場合

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

解決方法

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.

主な違い

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.

どちらをいつ使うか

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.

詳しく見る