WebSocket 1001 Going Away vs 1008 Policy Violation
Both WebSocket 1001 (Going Away) and 1008 (Policy Violation) 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, 1008 means 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.
Mô tả
An endpoint is going away, such as a server shutting down or a browser navigating away from the page. The connection must be closed.
Khi bạn thấy mã này
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.
Cách khắc phục
Implement automatic reconnection logic with exponential backoff in your client. If the server is restarting, the client should retry after a short delay.
Mô tả
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.
Khi bạn thấy mã này
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.
Cách khắc phục
Review the server's documented policies and constraints. Check for rate limiting, authentication token expiry, or forbidden message content that triggered the rejection.
Sự khác biệt chính
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.
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.
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.
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.
Khi nào dùng cái nào
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 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.