Skip to content

Release unfinished events when a BroadcastQueue subscriber is removed - #846

Open
DeepanshuPal wants to merge 4 commits into
livekit:mainfrom
DeepanshuPal:DeepanshuPal-patch-1
Open

DeepanshuPal wants to merge 4 commits into
livekit:mainfrom
DeepanshuPal:DeepanshuPal-patch-1

Conversation

@DeepanshuPal

Copy link
Copy Markdown

Fixes #827.

Room._listen_task calls BroadcastQueue.join() after each event. BroadcastQueue.unsubscribe() removed the subscriber's queue from _subscribers, but a join() already waiting on that queue kept waiting for events nobody would finish. When publish_track() is cancelled, its subscriber goes away mid-event and the room listener hangs, so no further room events are delivered.

This adds Queue.release(), which marks every unfinished item as done, and calls it from unsubscribe(). It covers events still queued and events the subscriber took with get() but never task_done()d.

Tests: livekit-rtc/tests/test_broadcast_queue.py (5 tests). 3 fail without the change (a join stays stuck after unsubscribe, with the event queued or already taken, and a surviving subscriber case), all 5 pass with it.

Disclosure: I used AI assistance to write this. I ran the tests locally before opening the PR.

Add release method to mark unfinished tasks as done.
Added unit tests for BroadcastQueue subscriber removal behavior, ensuring proper handling of joins and unsubscribes.

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

This branch has not been deployed

No deployments
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.

Cancelling a track publication waiter can strand Room._listen_task in BroadcastQueue.join

1 participant