Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/unpublish_from_remote_track_before_closing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
livekit: patch
livekit-ffi: patch
---

Unpublish from remote track participants before shutting down the RTC Engine to avoid leaking memory.
7 changes: 7 additions & 0 deletions livekit/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,13 @@ impl RoomSession {
let _ = self.local_participant.unpublish_track(sid).await;
}

// remove published remote tracks as well
for (_, participant) in self.remote_participants.read().clone() {
for (sid, _) in participant.track_publications() {
participant.unpublish_track(&sid);
Comment on lines +1176 to +1178

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.

🟡 Concurrent updates survive room closure

If an update arrives while close awaits engine shutdown, the earlier snapshot misses its participant or track. The closed room retains that publication.

Prompt for agents
RoomSession::close cleans remote participant publications while room_task can still process EngineEvent::ParticipantUpdate and EngineEvent::MediaTrack. Because both the participant map and each publication map are snapshots, updates handled after those snapshots can add publications that survive closure. Reorder teardown so no room event can mutate remote participants before the final remote-publication cleanup, while preserving delivery of TrackUnsubscribed and TrackUnpublished events and the existing local-track shutdown requirements. Add a concurrency-focused test that queues a participant or track update during close and verifies every retained RemoteParticipant has no publications when close returns.
Devin Review

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

}
}

self.rtc_engine.close(reason).await;
self.e2ee_manager.cleanup();

Expand Down
Loading