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.
主要区别
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 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.
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 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.