WebSocket

WebSocket 1001 Going Away vs 1014 Bad Gateway

Both WebSocket 1001 (Going Away) and 1014 (Bad Gateway) 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, 1014 means that the server acting as a gateway or proxy received an invalid response from an upstream server it accessed while attempting to fulfill the request.

描述

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.

描述

The server acting as a gateway or proxy received an invalid response from an upstream server it accessed while attempting to fulfill the request.

何时出现

A reverse proxy or API gateway tried to establish a WebSocket connection to a backend server but received an invalid or no response. The upstream server may be down or misconfigured.

如何修复

Check the health of the upstream/backend WebSocket server. Verify the proxy configuration routes WebSocket upgrade requests correctly and that the backend is listening on the expected port.

主要区别

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 1014: The server acting as a gateway or proxy received an invalid response from an upstream server it accessed while attempting to fulfill the request.

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 1014 when a reverse proxy or API gateway tried to establish a WebSocket connection to a backend server but received an invalid or no response. The upstream server may be down or misconfigured.

何时使用哪个

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 1014 (Bad Gateway): Check the health of the upstream/backend WebSocket server. Verify the proxy configuration routes WebSocket upgrade requests correctly and that the backend is listening on the expected port.

了解更多