What happens when a WebSocket connection is lost?

Answer

When a WebSocket connection is lost unexpectedly (network drop, server restart, browser tab backgrounding on mobile), the close event fires with close code 1006 (abnormal closure — no close frame was received). The connection does not automatically reconnect — this is left to the application developer. The standard approach is exponential backoff reconnection: attempt reconnection after 1s, then 2s, 4s, 8s, up to a maximum interval (e.g., 30s), to avoid overwhelming the server. Socket.IO handles this automatically. Libraries like ReconnectingWebSocket wrap the native WebSocket with automatic reconnection logic. During reconnection, the application must handle state: queue messages sent during disconnection, or notify the user of the interrupted connection and allow manual retry.