Skip to content

Remove published remote tracks in RoomSession::close() - #1382

Open
raparanjpe wants to merge 1 commit into
livekit:mainfrom
raparanjpe:close_after_unpublish
Open

Remove published remote tracks in RoomSession::close()#1382
raparanjpe wants to merge 1 commit into
livekit:mainfrom
raparanjpe:close_after_unpublish

Conversation

@raparanjpe

Copy link
Copy Markdown

Closes #1378

The idea here is to follow a similar procedure to fn handle_participant_disconnect where we handle participant disconnects, but we should also do so when closing out a room.

@raparanjpe
raparanjpe requested a review from ladvoc as a code owner August 31, 2026 03:41

@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 1 potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment thread livekit/src/room/mod.rs
Comment on lines +1176 to +1178
for (_, participant) in self.remote_participants.read().clone() {
for (sid, _) in participant.track_publications() {
participant.unpublish_track(&sid);

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.

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.

Memory Leak with Multiple Remote Publishers

1 participant