Skip to content

fix: force-clear WebSocket session from memory on disconnect#312

Merged
Sadeequ merged 1 commit into
StellarFlow-Network:mainfrom
nyarumyaro:fix/websocket-room-cleanup-294
May 29, 2026
Merged

fix: force-clear WebSocket session from memory on disconnect#312
Sadeequ merged 1 commit into
StellarFlow-Network:mainfrom
nyarumyaro:fix/websocket-room-cleanup-294

Conversation

@nyarumyaro
Copy link
Copy Markdown
Contributor

Summary

Fixes #294 — corrupted WebSocket room cleanup logic.

When an admin closes or refreshes the dashboard browser tab abruptly, the backend was entering a 60-second grace period before removing the dead socket session from memory. This caused stale disconnected-pending entries to accumulate in the sessions map, creating unnecessary memory overhead.

Changes

src/lib/socket.tshandleDisconnect

  • Removed the 60-second grace period / disconnectTimer timeout on disconnect.
  • Session is now immediately deleted from the sessions map when a disconnect event fires.
  • Any previously scheduled disconnectTimer is cancelled before deletion to avoid dangling timers.

Before / After

// Before: session entered grace period for 60s
session.status = "disconnected-pending";
session.disconnectTimer = setTimeout(() => sessions.delete(sessionId), 60000);

// After: session is force-cleared immediately
if (session.disconnectTimer) clearTimeout(session.disconnectTimer);
sessions.delete(sessionId);

Testing

  • Connect a Socket.IO client, then abruptly close the connection.
  • Verify the session is removed from the sessions map immediately (no 60s wait).
  • Verify no memory growth from repeated abrupt disconnects.

On abrupt disconnect (e.g. browser tab close/refresh), the previous
implementation entered a 60s grace period before removing the session,
leaving dead socket connections in memory.

Now handleDisconnect immediately deletes the session from the sessions
map and cancels any pending disconnectTimer, preventing memory overhead
from stale connections.

Closes StellarFlow-Network#294
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@nyarumyaro 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

@Sadeequ Sadeequ merged commit 694dccf into StellarFlow-Network:main May 29, 2026
1 check failed
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.

🔄 Fix | Corrupted WebSocket Room Cleanup Logic

2 participants