Skip to content

fix: dispose track publication handles on participant disconnect#634

Open
LautaroPetaccio wants to merge 6 commits intolivekit:mainfrom
LautaroPetaccio:fix/dispose-track-publications-on-disconnect
Open

fix: dispose track publication handles on participant disconnect#634
LautaroPetaccio wants to merge 6 commits intolivekit:mainfrom
LautaroPetaccio:fix/dispose-track-publications-on-disconnect

Conversation

@LautaroPetaccio
Copy link
Copy Markdown

Why

When the room processes a participantDisconnected event, it deletes the participant from the remoteParticipants map and emits an event — but never touches the participant's trackPublications. Each TrackPublication wraps an FfiHandle that maps to a native resource. Dropping the JS reference without calling dispose() means the native side never frees the handle. With N participants each publishing M tracks, every disconnect leaks N×M handles.

How

In the participantDisconnected event handler, before emitting the event, loop through participant.trackPublications, call ffiHandle.dispose() on each publication, and clear the map.

Test coverage

  • cleans up track publications when a remote participant disconnects — publishes a track, disconnects the publisher, asserts trackPublications is empty on the observer side
  • cleans up resources when multiple participants disconnect simultaneously — 4 participants each with a track, all disconnect at once

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 1, 2026

🦋 Changeset detected

Latest commit: b1cd48c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@livekit/rtc-node Patch

Not sure what this means? Click here to learn what changesets are.

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

devin-ai-integration[bot]

This comment was marked as resolved.

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.

1 participant