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