WebSocket

WebSocket 1000 Normal Closure vs 1011 Internal Error

Both WebSocket 1000 (Normal Closure) and 1011 (Internal Error) belong to the WebSocket Close Codes category. 1000 indicates that the connection has been closed cleanly, meaning the purpose for which it was established has been fulfilled. Both endpoints agree the session is complete. Meanwhile, 1011 means that the server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

描述

The connection has been closed cleanly, meaning the purpose for which it was established has been fulfilled. Both endpoints agree the session is complete.

何时出现

The WebSocket connection closed gracefully after both sides finished exchanging data. This is the expected close code for a successful session.

如何修复

No fix needed — this indicates everything worked as intended. If you did not expect the connection to close, check your application logic for premature close() calls.

描述

The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

何时出现

The server hit an unhandled exception or crashed while processing a WebSocket message. This is the WebSocket equivalent of HTTP 500 Internal Server Error.

如何修复

Check the server-side application logs for stack traces and exceptions. Fix the underlying bug that caused the crash and add proper error handling around message processing.

主要区别

1.

WebSocket 1000: The connection has been closed cleanly, meaning the purpose for which it was established has been fulfilled. Both endpoints agree the session is complete.

2.

WebSocket 1011: The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

3.

You encounter 1000 when the WebSocket connection closed gracefully after both sides finished exchanging data. This is the expected close code for a successful session.

4.

You encounter 1011 when the server hit an unhandled exception or crashed while processing a WebSocket message. This is the WebSocket equivalent of HTTP 500 Internal Server Error.

何时使用哪个

For 1000 (Normal Closure): No fix needed — this indicates everything worked as intended. If you did not expect the connection to close, check your application logic for premature close() calls. For 1011 (Internal Error): Check the server-side application logs for stack traces and exceptions. Fix the underlying bug that caused the crash and add proper error handling around message processing.

了解更多