Skip to content

fix: release RTP transceiver and FFI handle resources when unpublishing a track - #1381

Open
OlympusM wants to merge 7 commits into
livekit:mainfrom
OlympusM:fix-videotrackunpublication-leak
Open

fix: release RTP transceiver and FFI handle resources when unpublishing a track#1381
OlympusM wants to merge 7 commits into
livekit:mainfrom
OlympusM:fix-videotrackunpublication-leak

Conversation

@OlympusM

Copy link
Copy Markdown
Contributor

Problem

When a local track is unpublished, some resources associated with it were never released:

  • On the FFI server, the RtpSender was removed from the peer connection, but the underlying RtpTransceiver was never stopped, so it stayed alive.
  • The FFI local_publication_lookup map had no corresponding cleanup, so the publication's server handle was never dropped after unpublishing, leaking the handle.

This meant repeated publish/unpublish cycles would accumulate resources that were never freed which was especially bad on a video track.

Fix

  • LocalParticipant::unpublish_track now grabs the RtpTransceiver (instead of just its RtpSender) and passes it through RtcEngine::remove_track / RtcSession::remove_track, which now call transceiver.stop() after removing the sender from the peer connection.
  • remove_track signatures were updated from RtpSender to RtpTransceiver across local_participant.rs, rtc_engine/mod.rs, and rtc_session.rs; the sender is now derived from the transceiver internally where needed.
  • The FFI server now tracks each published track's handle in local_publication_lookup on publish, and removes + drops that handle on unpublish (room.rs), preventing the FFI-side leak as well.

Notes

  • I have been testing this locally for a while now on a private application that is built on top of LiveKit.

@OlympusM
OlympusM requested a review from ladvoc as a code owner August 31, 2026 02:16
devin-ai-integration[bot]

This comment was marked as resolved.

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