Skip to content

Preserve room sessions across deploys#178

Draft
coder13 wants to merge 2 commits into
devfrom
agent/deploy-safe-reconnect
Draft

Preserve room sessions across deploys#178
coder13 wants to merge 2 commits into
devfrom
agent/deploy-safe-reconnect

Conversation

@coder13

@coder13 coder13 commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • add a configurable reconnect grace period before removing authenticated users from rooms
  • reconcile room membership against globally active Socket.IO connections through the Redis adapter
  • preserve room, scramble, waiting/competing, and admin state across socket process replacement
  • remove startup and API shutdown paths that destructively cleared room membership
  • build and migrate before replacing application containers, keep stateful services intact, and gracefully reload nginx after each handoff
  • expose dependency-aware API/socket HTTP health endpoints and a Socket.IO health event
  • document the deployment behavior, health checks, and ROOM_RECONNECT_GRACE_MS

Root cause

Socket startup previously marked every normal room stale, cleared each user's inRoom and waitingFor values, and removed the room admin. Normal socket disconnects also removed users immediately, while the API SIGINT handler dropped every user from every room. A routine process replacement could therefore mutate persistent race state before clients had time to reconnect.

The previous container health checks only verified that the API returned a non-500 response and that Engine.IO accepted a polling handshake. They did not report whether MongoDB, PostgreSQL, or Redis were actually available.

Impact

Authenticated clients with the room page still open automatically reconnect and resume the same room within the grace window (60 seconds by default). The server verifies membership using the shared Redis adapter, so reconnects to another Socket.IO instance are recognized. Explicit leaves, kicks, and bans remain immediate.

The socket transport may briefly disconnect while its container is replaced, but that disconnect no longer ends the user's room session or advances room state.

Operators can query /health/api and /health/socket for dependency-level readiness, or emit health_check on the default Socket.IO namespace to verify a real socket round trip. Compose now uses the explicit readiness endpoints.

Validation

  • yarn lint
  • yarn test (40 server tests and 17 client tests)
  • yarn build
  • bash -n scripts/deploy.sh
  • docker compose -f compose.yml -f compose.prod.yml config -q
  • git diff --check

coder13 added 2 commits July 10, 2026 08:24
Delay disconnect cleanup while clients reconnect and reconcile membership through the shared Redis adapter. Deploy application services sequentially without recreating stateful dependencies.
Expose dependency-aware HTTP readiness endpoints and a Socket.IO health round trip. Point Compose and nginx at the explicit health routes for deployment verification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant