Skip to content

Fix LocalTrackPublished handle leak#1065

Draft
MaxHeimbrock wants to merge 1 commit intomainfrom
max/fix-local-track-published-handle-leak
Draft

Fix LocalTrackPublished handle leak#1065
MaxHeimbrock wants to merge 1 commit intomainfrom
max/fix-local-track-published-handle-leak

Conversation

@MaxHeimbrock
Copy link
Copy Markdown
Contributor

Summary

The forward_event handler for RoomEvent::LocalTrackPublished was allocating a fresh FfiPublication, calling FfiServer::store_handle, and then sending the proto event without the handle id. Because proto::LocalTrackPublished only carries track_sid, the foreign-language client never received the id and had no way to call drop_handle on it. Each local publish_track call therefore leaked one publication entry in the FFI handle table for the lifetime of the process.

The publication is already wrapped and handed to the client via the PublishTrackCallback path. The LocalTrackPublished event is a notification that fires after that callback to let the client run any post-publish bookkeeping; it does not need its own handle. Drop the redundant allocation entirely.

Surfaced while investigating untracked memory growth in the Unity SDK, where the FFI handle table held two publication entries per local track across a session and only one of them could be dropped on disconnect.

Test plan

  • Verified with an FFI handle table diagnostic that local publish + disconnect drops to zero residual publication handles.
  • CI tests pass.

🤖 Generated with Claude Code

The forward_event handler for RoomEvent::LocalTrackPublished was allocating
a fresh FfiPublication, calling FfiServer::store_handle, and then sending the
proto event without the handle id. Because proto::LocalTrackPublished only
carries track_sid, the foreign-language client never received the id and had
no way to call drop_handle on it. Each local publish_track call therefore
leaked one publication entry in the FFI handle table for the lifetime of
the process.

The publication is already wrapped and handed to the client via the
PublishTrackCallback path (publish_track at the top of this file). The
LocalTrackPublished event is a notification that fires after that callback
to let the client run any post-publish bookkeeping; it does not need its
own handle. Drop the redundant allocation entirely.

Surfaced while investigating untracked memory growth in the Unity SDK,
where the FFI handle table held two publication entries per local track
across a session and only one of them could be dropped on disconnect.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

No changeset found

This PR modifies the following packages but doesn't include a changeset:

Directly changed:

  • livekit-ffi

Click here to create a changeset

The link pre-populates a changeset file with patch bumps for all affected packages.
Edit the description and bump types as needed before committing.

If this change doesn't require a version bump, add the internal label to this PR.

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