WebSocket

WebSocket 1001 Going Away vs 1002 Protocol Error

Both WebSocket 1001 (Going Away) and 1002 (Protocol Error) belong to the WebSocket Close Codes category. 1001 indicates that an endpoint is going away, such as a server shutting down or a browser navigating away from the page. The connection must be closed. Meanwhile, 1002 means that an endpoint is terminating the connection because it received data that violates the WebSocket protocol specification.

الوصف

An endpoint is going away, such as a server shutting down or a browser navigating away from the page. The connection must be closed.

متى تراه

The server is shutting down for maintenance, or the user navigated away from the page or closed the browser tab while a WebSocket was open.

كيفية الإصلاح

Implement automatic reconnection logic with exponential backoff in your client. If the server is restarting, the client should retry after a short 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.

الفروق الرئيسية

1.

WebSocket 1001: An endpoint is going away, such as a server shutting down or a browser navigating away from the page. The connection must be closed.

2.

WebSocket 1002: An endpoint is terminating the connection because it received data that violates the WebSocket protocol specification.

3.

You encounter 1001 when the server is shutting down for maintenance, or the user navigated away from the page or closed the browser tab while a WebSocket was open.

4.

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.

متى تستخدم أيًا منهما

For 1001 (Going Away): Implement automatic reconnection logic with exponential backoff in your client. If the server is restarting, the client should retry after a short delay. 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.

اعرف المزيد