Skip to content

Fix persistence workers never terminating #401

Merged
paulgb merged 1 commit into
jamsocket:mainfrom
Dracyr:pv/fix-persistence-worker-shutdown
Jun 13, 2025
Merged

Fix persistence workers never terminating #401
paulgb merged 1 commit into
jamsocket:mainfrom
Dracyr:pv/fix-persistence-worker-shutdown

Conversation

@Dracyr

@Dracyr Dracyr commented May 28, 2025

Copy link
Copy Markdown
Contributor

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.

@vercel

vercel Bot commented May 28, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
y-sweet-debugger ⬜️ Ignored (Inspect) Visit Preview May 28, 2025 5:54am
y-sweet-gendocs ⬜️ Ignored (Inspect) Visit Preview May 28, 2025 5:54am

@vercel

vercel Bot commented May 28, 2025

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the drifting-corp Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread crates/y-sweet/src/server.rs Outdated
@Dracyr Dracyr force-pushed the pv/fix-persistence-worker-shutdown branch from a14fe2e to 90972d7 Compare May 28, 2025 05:53
@Aidan-bw

Copy link
Copy Markdown

Looks like a great change. Is there any reason this shouldn't be pushed?

@paulgb

paulgb commented Jun 12, 2025

Copy link
Copy Markdown
Member

Looks like a great change. Is there any reason this shouldn't be pushed?

Thanks for the reminder! No good reason, I was just traveling for a couple weeks and didn't have a chance yet.

@paulgb paulgb merged commit 3707844 into jamsocket:main Jun 13, 2025
8 of 12 checks passed
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>
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.

3 participants