WebSocket

WebSocket 1002 Protocol Error vs 1012 Service Restart

Both WebSocket 1002 (Protocol Error) and 1012 (Service Restart) belong to the WebSocket Close Codes category. 1002 indicates that an endpoint is terminating the connection because it received data that violates the WebSocket protocol specification. 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 data that violates the WebSocket protocol specification.

เมื่อคุณพบเห็น

The WebSocket frame format is invalid — a malformed header, incorrect masking, or a reserved opcode was used. This usually indicates a broken client or proxy.

วิธีแก้ไข

Check that both client and server strictly follow RFC 6455 framing rules. Inspect intermediary proxies that may be corrupting WebSocket frames.

คำอธิบาย

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 1002: An endpoint is terminating the connection because it received data that violates the WebSocket protocol specification.

2.

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

3.

You encounter 1002 when the WebSocket frame format is invalid — a malformed header, incorrect masking, or a reserved opcode was used. This usually indicates a broken client or proxy.

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 1002 (Protocol Error): Check that both client and server strictly follow RFC 6455 framing rules. Inspect intermediary proxies that may be corrupting WebSocket frames. 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.

เรียนรู้เพิ่มเติม