Skip to main content

WebSocket Close Codes

WebSocket connections close with a numeric code and optional reason string. Codes 1000–1015 are defined in RFC 6455. Understanding these codes is essential for implementing correct reconnection logic.

CodeName & DescriptionSent ByRetry
1000

Normal Closure

1000 Normal Closure indicates the WebSocket connection was closed cleanly and intentionally by either endpoint.

bothNo
1001

Going Away

1001 Going Away indicates the endpoint is 'going away' – a server is shutting down or restarting, or a browser tab is being closed.

bothYes
1002

Protocol Error

1002 Protocol Error indicates the endpoint is terminating the connection because the peer violated the WebSocket protocol.

bothNo
1003

Unsupported Data

1003 Unsupported Data is sent when an endpoint receives a data type it cannot handle – typically a binary message when only text is supported, or vice versa.

bothNo
1005

No Status Received

1005 No Status Received is a reserved code used internally by WebSocket libraries to indicate the TCP connection was closed without a WebSocket close frame.

reservedYes
1006

Abnormal Closure

1006 Abnormal Closure is a reserved code used by WebSocket libraries when the connection was closed abnormally – without a close handshake and without a specific error code.

reservedYes
1007

Invalid Frame Payload Data

1007 Invalid Frame Payload Data is sent when a text message frame contains data that is not valid UTF-8.

bothNo
1008

Policy Violation

1008 Policy Violation is a generic close code for when an endpoint receives a message that violates its policies – authorization failure, rate limiting, content policy enforcement, or a custom application rule.

bothNo
1009

Message Too Big

1009 Message Too Big is sent when an endpoint receives a message that exceeds the maximum message size it is configured to accept.

bothNo
1011

Internal Server Error

1011 Internal Server Error is sent by a server when an unexpected condition prevented it from processing a client request.

serverYes
1012

Service Restart

1012 Service Restart is sent when a server is restarting for a non-error reason – planned restart, deployment, or maintenance.

serverYes
1013

Try Again Later

1013 Try Again Later is sent when the server is temporarily unable to accept new connections due to overload or temporary unavailability.

serverYes
1014

Bad Gateway

1014 Bad Gateway is sent when a server acting as a gateway or proxy receives an invalid response from an upstream WebSocket server.

bothYes
1015

TLS Handshake Failure

1015 TLS Handshake Failure is a reserved code that indicates the WebSocket connection was closed because the TLS (wss://) handshake failed.

reservedNo