fix: add periodic purge job for empty collaboration rooms#1166
Open
rachel-d-07 wants to merge 2 commits into
Open
fix: add periodic purge job for empty collaboration rooms#1166rachel-d-07 wants to merge 2 commits into
rachel-d-07 wants to merge 2 commits into
Conversation
Fixes imDarshanGK#1129 - rooms where all clients drop abruptly (tab close, network failure) are never cleaned up because stale_clients in broadcast() is only processed when a broadcast fires. Adds a 30-minute APScheduler interval job that sweeps manager.rooms and removes any room with no active sockets, preventing unbounded memory growth over the server lifetime.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1129 - rooms where all clients drop abruptly (tab close, network failure) are never cleaned up because stale_clients in broadcast() is only processed when a broadcast fires. Adds a 30-minute APScheduler interval job that sweeps manager.rooms and removes any room with no active sockets, preventing unbounded memory growth over the server lifetime.
Description
Collaboration rooms where all clients disconnect abruptly (tab close,
browser crash, network failure) were never removed from
CollaborationManager.rooms. The existing stale socket cleanup inbroadcast()only runs when a message is sent — if no broadcast firesafter all clients drop, the room leaks in memory indefinitely with
empty sockets/users but full code and comments state retained.
Added a
_purge_empty_collab_rooms()job inbackend/app/services/scheduler.pythat runs every 30 minutes viaAPScheduler and removes any room where
len(room.sockets) == 0.No changes to
collaboration.py— fix is entirely in the scheduler.Related Issue
Fixes #1129
Type of change
Checklist
mainpytest -vand all tests passfeat/fix/docs/test: short descriptionScreenshots (if frontend change)
N/A — backend-only change, no UI affected.
Test evidence
Local environment does not have all backend dependencies configured
for a full pytest run. The fix is verified by code inspection:
_purge_empty_collab_rooms()iteratesmanager.roomssafely vialist()copy to avoid mutation during iterationroom.socketsis empty (falsy dict)replace_existing=Trueso restarts don't duplicatethe job