Graceful WS reconnect with exponential back-off #52

Open
opened 2026-04-19 07:23:42 +00:00 by forgejo-lila · 0 comments
Owner

Context

WebSocket connections can drop. During active games, recovery should be seamless.

Files to change

  • apps/web/src/lib/ws-client.ts — reconnection logic.
  • apps/api/src/ws/handlers/lobbyHandlers.ts — handle rejoin.

Client behavior

  • On disconnect: exponential back-off (1s, 2s, 4s, 8s, max 30s).
  • Show 'Reconnecting...' overlay.
  • On reconnect: send lobby:rejoin { lobbyId }.
  • If game ended during disconnect: show final results.
  • After max retries: 'Connection lost' with manual retry.

Server behavior

  • On lobby:rejoin: validate player was in lobby, re-associate WebSocket, send current state.
  • Grace period (30s) before considering disconnected.
  • After grace: treat as leave.

Acceptance criteria

  • Brief disconnects (<30s) recovered without losing state
  • Player rejoins in progress and sees current question
  • Other players see reconnecting status
  • Permanent disconnects free the slot
  • Works on mobile (phone sleep scenario)

Notes

Consider implementing basic reconnection first, defer game state recovery to follow-up.

## Context WebSocket connections can drop. During active games, recovery should be seamless. ## Files to change - `apps/web/src/lib/ws-client.ts` — reconnection logic. - `apps/api/src/ws/handlers/lobbyHandlers.ts` — handle rejoin. ## Client behavior - On disconnect: exponential back-off (1s, 2s, 4s, 8s, max 30s). - Show 'Reconnecting...' overlay. - On reconnect: send `lobby:rejoin { lobbyId }`. - If game ended during disconnect: show final results. - After max retries: 'Connection lost' with manual retry. ## Server behavior - On `lobby:rejoin`: validate player was in lobby, re-associate WebSocket, send current state. - Grace period (30s) before considering disconnected. - After grace: treat as leave. ## Acceptance criteria - Brief disconnects (<30s) recovered without losing state - Player rejoins in progress and sees current question - Other players see reconnecting status - Permanent disconnects free the slot - Works on mobile (phone sleep scenario) ## Notes Consider implementing basic reconnection first, defer game state recovery to follow-up.
forgejo-lila added the
multiplayer
label 2026-04-19 07:23:42 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: forgejo-lila/lila#52
No description provided.