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.

Mô tả

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

Khi bạn thấy mã này

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

Cách khắc phục

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.

Mô tả

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

Khi bạn thấy mã này

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

Cách khắc phục

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.

Sự khác biệt chính

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.

Khi nào dùng cái nào

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.

Tìm hiểu thêm