Repository navigation
fix(rtc): end AudioMixer iteration when endInput() runs with no streams left - #744
Open
Abhishek-B-R wants to merge 1 commit into
Open
Abhishek-B-R wants to merge 1 commit into
Abhishek-B-R wants to merge 1 commit into
Conversation
…ms left When the last stream has been removed (or none was ever added), the mixer task parks on the stream signal queue waiting for an addStream() that can no longer happen. endInput() only set the ending flag, so nothing woke the task, the output queue was never closed, and a consumer already waiting in for await stayed blocked forever. endInput() now closes the stream signal queue, so the parked task wakes, sees it is ending with no streams, exits and closes the output queue.
🦋 Changeset detectedLatest commit: c2a1096 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
If a consumer is already waiting on
for await (const frame of mixer)andendInput()is called after the last stream was removed (or before any was added), the loop never ends.When there are no streams, the mixer task parks on
streamSignal.waitForItem()untiladdStream()puts a signal.endInput()only setsthis.ending = true, so nothing wakes that task. It never reaches theending && streams.size === 0check at the top of its loop, so it never closes the output queue, and the consumer parked inqueue.waitForItem()waits forever. The existing "handles empty mixer" test passes only because it callsendInput()before it starts iterating, sogetNextFrame()sees the flag on its first check.The Python mixer does not have this problem: its
_mixerloop sleeps 10ms and rechecks_endingwhen there are no streams, soend_input()is always noticed.Fix
endInput()also closesstreamSignal. A parked mixer task wakes, sees it is ending with no streams, breaks, and closes the output queue, which releases the consumer. When streams are still active nothing changes: the task does not touchstreamSignalwhile it has streams, and it still drains them until they are exhausted.addStream()afterendInput()already throws, so the closed signal queue is never written to again.Testing
Two tests in
audio_mixer.test.ts, each giving the consumer 1s to finish afterendInput():consumer waiting, no streams ever added, then
endInput()consumer waiting, a silent stream added and removed, then
endInput()Before the change: both fail with
expected 'hung' to deeply equal [], 8 passed, 2 failed.After: 10 of 10 pass in
src/audio_mixer.test.ts(473ms, down from 2.48s with the two hangs), and 22 of 22 acrossaudio_mixerandasync_queueon 15 repeated runs.npx vitest run srcinpackages/livekit-rtc: all unit tests pass. The two e2e files fail to load on main too, because they need a builtlivekit-server-sdkand a live server.tsc --noEmit,pnpm lintand prettier report nothing in the changed files.A patch changeset for
@livekit/rtc-nodeis included.