Skip to content

finalization strategy for worker listeners - #2079

Open
lukasIO wants to merge 6 commits into
lukas/forward-worker-logsfrom
lukas/e2ee-dispose
Open

finalization strategy for worker listeners#2079
lukasIO wants to merge 6 commits into
lukas/forward-worker-logsfrom
lukas/e2ee-dispose

Conversation

@lukasIO

@lukasIO lukasIO commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@changeset-bot

changeset-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3a8f294

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment thread src/e2ee/E2eeManager.ts
Comment thread src/e2ee/E2eeManager.ts
Comment on lines +196 to +199
if (this.worker) {
this.worker.onmessage = null;
this.worker.onerror = null;
}

@devin-ai-integration devin-ai-integration Bot Sep 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Disposal erases replacement worker handlers

If the worker owner replaces a handler after setup, dispose() clears it unconditionally. Later worker messages lose the owner's handler.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 111.12 KB (+0.11% 🔺)
dist/livekit-client.umd.js 120.34 KB (+0.15% 🔺)

Comment thread src/e2ee/E2eeManager.ts
Comment on lines +93 to +103
/**
* Runs a cleanup callback once this manager is garbage collected. Lets the
* log-level listener (held in a module-global Set on the main-thread logger)
* fall out of scope even when the consumer forgets to call `dispose()`.
*/
private static disposeRegistry =
typeof FinalizationRegistry !== 'undefined' &&
typeof WeakRef !== 'undefined' &&
new FinalizationRegistry((cleanup: () => void) => {
cleanup();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Have you been able to actually verify this runs? I think there's a reference cycle between E2eeManager and Room currently (E2eeManager.room and Room.e2eeManager) so I'm not convinced without breaking this cycle that E2eeManager would ever get garbage collected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, that this won't work on its own, or rather won't address the issues around the cyclical Room references.
My intention was to set up everything in a way that would allow for it to get dropped once the cyclical room references are taken care of.
Addressing this is out of scope for this PR however.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added tests to verify the cleanup works without room references as expected, the value of that is somewhat questionable within the greater picture, but it allows us to verify the cleanup logic within the module works as expected.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I suppose this does set us up well to have this all working once we can break that reference cycle. It doesn't have to be part of this PR, but I wonder if it could be prudent to introduce that room.dispose() type method we talked about in a 1:1 sooner rather than later and that could be used as a way to trigger this in the more near term.

Comment thread src/e2ee/E2eeManager.ts
Comment thread src/e2ee/E2eeManager.ts
// response can't resolve one after we've cut the pipe. Each future's
// `onFinally` deletes its own map entry, so both maps drain themselves.
// Snapshot before iterating in case a rejection handler mutates the map.
const disposalError = new Error('E2EEManager disposed');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Maybe this should be a custom error type?

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.

2 participants