Skip to content

#221 Presence recovery after gateway restart FIXED#262

Open
felladaniel36-hash wants to merge 1 commit into
codebestia:mainfrom
felladaniel36-hash:#221-Presence-recovery-after-gateway-restart-FIX
Open

#221 Presence recovery after gateway restart FIXED#262
felladaniel36-hash wants to merge 1 commit into
codebestia:mainfrom
felladaniel36-hash:#221-Presence-recovery-after-gateway-restart-FIX

Conversation

@felladaniel36-hash

Copy link
Copy Markdown

Description

This PR resolves an issue where online presence tracking and room subscriptions were lost during a gateway (backend instance) restart.

Specifically, it introduces three key changes:

  1. Gateway Restart Protection: Hooks server shutdown lifecycle events (SIGTERM, SIGINT, httpServer.close(), io.close()) to set an isShuttingDown flag. During a server shutdown or namespace restart, socket.on('disconnect') skips asserting setOffline(), preserving active user presence mappings in Redis.
  2. Boot Room Subscription Reconciliation (reconcileBoot): Adds a reconciliation routine that runs on gateway boot once the Socket.IO Redis adapter attaches. It scans active presence:* keys in Redis, queries PostgreSQL for user conversation memberships, and rebuilds room subscriptions via io.in(socketId).socketsJoin(conversationId).
  3. Stale/Duplicate Socket Cleanup (cleanupStaleSockets): On socket connection, heartbeat, and disconnect, existing socket IDs stored in presence:{userId} are checked against active sockets in the cluster (io.in(sid).fetchSockets()). Dead sockets from prior restarts are purged immediately, preventing duplicate presence entries.

Type of change

  • Bug fix

  • New feature

  • Documentation update

  • Other

Checklist

  • I have read the contributing guidelines

  • I have tested my changes locally

  • My code follows the project's coding standards

CLOSE #221

@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@felladaniel36-hash Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@codebestia

Copy link
Copy Markdown
Owner

Hello @felladaniel36-hash
Please fix the conflicts and ensure the CI passes.
Thanks

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.

Presence recovery after gateway restart

2 participants