Does Socket.IO connection state recovery survive a server restart, or do I need external persistence?
0 reputation · 28 Jan 2021, 05:58 UTC
0 reputation · 28 Jan 2021, 05:58 UTC
I want clients that briefly lose connectivity to receive the events they missed and keep their room memberships after reconnecting, even if the Socket.IO server process restarts during the outage.
Assume Socket.IO v4.6+ on both server and client, with connectionStateRecovery enabled and a configured maxDisconnectionDuration. As documented, recovery state—session identity, rooms, and missed packets—is held in server memory by default. That implies a restart or crash inside the disconnection window discards it, and the reconnecting client is treated as brand new. In a multi-node setup I also understand room and recovery state is per node unless a compatible adapter (e.g., Redis) is configured, though I have not verified how that interacts with recovery specifically.
The documented alternative for durability is building at-least-once delivery myself using acknowledgements with timeouts (socket.timeout(ms).emit) plus client-side buffering or a custom event queue.
35275 reputation · 28 Jan 2021, 15:36 UTC
Socket.IO connection state recovery does not survive server restarts. The recovery state—including session identity, room memberships, and missed packets—is stored in server memory only. When the server process restarts, this state is lost and reconnecting clients are treated as new connections.
According to Socket.IO v4.6+ documentation and implementation:
connectionStateRecovery plugin maintains state exclusively in memorymaxDisconnectionDuration settingsConfiguring the Redis adapter synchronizes room membership and broadcast messaging across multiple nodes, but it does not persist connection recovery state. The adapter stores room data in Redis, yet session-specific recovery information remains in each node's local memory. A node restart still discards its clients' recovery context.
To achieve at-least-once delivery across restarts, combine Socket.IO with application-level persistence:
socket.timeout(ms).emit() for critical messagesTo confirm this behavior in your environment:
socket.on('connect') without socket.on('recovered') eventssocket.rooms is empty post-restart unless client rejoins programmaticallyCan you confirm whether you're using a single server instance or a multi-node cluster? This affects whether Redis adapter setup is already in place for room synchronization.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.