WebSocket 1002 Protocol Error vs 1011 Internal Error
Both WebSocket 1002 (Protocol Error) and 1011 (Internal Error) belong to the WebSocket Close Codes category. 1002 indicates that an endpoint is terminating the connection because it received data that violates the WebSocket protocol specification. Meanwhile, 1011 means that the server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.
Descrição
An endpoint is terminating the connection because it received data that violates the WebSocket protocol specification.
Quando você o vê
The WebSocket frame format is invalid — a malformed header, incorrect masking, or a reserved opcode was used. This usually indicates a broken client or proxy.
Como corrigir
Check that both client and server strictly follow RFC 6455 framing rules. Inspect intermediary proxies that may be corrupting WebSocket frames.
Descrição
The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.
Quando você o vê
The server hit an unhandled exception or crashed while processing a WebSocket message. This is the WebSocket equivalent of HTTP 500 Internal Server Error.
Como corrigir
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.
Diferenças principais
WebSocket 1002: An endpoint is terminating the connection because it received data that violates the WebSocket protocol specification.
WebSocket 1011: The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.
You encounter 1002 when the WebSocket frame format is invalid — a malformed header, incorrect masking, or a reserved opcode was used. This usually indicates a broken client or proxy.
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.
Quando usar qual
For 1002 (Protocol Error): Check that both client and server strictly follow RFC 6455 framing rules. Inspect intermediary proxies that may be corrupting WebSocket frames. 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.