Fix persistence workers never terminating #401
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Skipped Deployments
|
|
Someone is attempting to deploy a commit to the drifting-corp Team on Vercel. A member of the Team first needs to authorize it. |
a14fe2e to
90972d7
Compare
|
Looks like a great change. Is there any reason this shouldn't be pushed? |
paulgb
approved these changes
Jun 12, 2025
Member
Thanks for the reminder! No good reason, I was just traveling for a couple weeks and didn't have a chance yet. |
dtkav
added a commit
to No-Instructions/relay-server
that referenced
this pull request
Feb 26, 2026
Re-add shutdown logic that was accidentally removed in ed4a438 (CBOR migration). Without this, persistence workers never terminate when docs are garbage collected, causing a memory leak. The fix adds a shutdown flag to SyncKv that the GC worker sets before removing a doc. The persistence worker periodically checks this flag and exits cleanly when set. This restores the fix originally implemented in PR jamsocket#401. Includes regression test that fails without the fix (workers hang) and passes with it. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Hey!
This PR fixes an issue where memory is never reclaimed and keeps rising, due to persistence workers never shutting down and freeing up the used memory.
I'm running y-sweet as a long-running service, instead of via Plane or another way to spin up a process per "room". And while experimenting I also allowed images to be uploaded to the room state, which made the fact that there was something up with the memory usage very visible, and after adding a bit of logging/monitoring I could see that the number of persistence workers never decreased.
In order to fix this, this PR adds a link between the GC Worker and the persistence worker. When the GC detects that there's no more references to the document it also notifies the persistence worker to shut down, and when it does the memory is also freed.