WebSocket

WebSocket 1001 Going Away vs 1005 No Status Received

Both WebSocket 1001 (Going Away) and 1005 (No Status Received) 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, 1005 means that a reserved value that indicates no status code was present in the Close frame. This code must not be set by an endpoint when sending a Close frame.

คำอธิบาย

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.

คำอธิบาย

A reserved value that indicates no status code was present in the Close frame. This code must not be set by an endpoint when sending a Close frame.

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

The peer closed the connection with a Close frame that contained no status code payload. Your WebSocket library surfaces 1005 as a sentinel to indicate the absence of a code.

วิธีแก้ไข

This is an internal indicator, not a wire protocol value. If you see it frequently, the remote peer may have a bug where it sends empty Close frames — check the peer's implementation.

ความแตกต่างหลัก

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 1005: A reserved value that indicates no status code was present in the Close frame. This code must not be set by an endpoint when sending a Close frame.

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 1005 when the peer closed the connection with a Close frame that contained no status code payload. Your WebSocket library surfaces 1005 as a sentinel to indicate the absence of a code.

ควรใช้อันไหนเมื่อไร

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 1005 (No Status Received): This is an internal indicator, not a wire protocol value. If you see it frequently, the remote peer may have a bug where it sends empty Close frames — check the peer's implementation.

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