Skip to content

fix(rtc): finish AudioMixer iteration when closed - #876

Open
Apeksha9389 wants to merge 3 commits into
livekit:mainfrom
Apeksha9389:fix/mixer-iteration-shutdown
Open

Apeksha9389 wants to merge 3 commits into
livekit:mainfrom
Apeksha9389:fix/mixer-iteration-shutdown

Conversation

@Apeksha9389

@Apeksha9389 Apeksha9389 commented Oct 20, 2026 •

Copy link
Copy Markdown

AudioMixer.aclose() cancels the producer without waking a consumer already awaiting the next frame. A task draining the mixer can therefore remain blocked after close returns. After end_input() finishes naturally, a second anext() also waits forever because the end marker was already consumed.

Track completed iteration explicitly and signal the output queue when closing. Immediate close discards queued output before inserting the end marker, so a full bounded queue cannot block shutdown. Natural end_input() still drains buffered audio before exhaustion. Readers retain the terminal marker so already-blocked readers can also observe it.

Three new regressions fail on unchanged main: a waiting consumer during close, repeated reads after natural exhaustion, and close with a full output queue. With the fix, all 37 tests in the mixer, FFI queue, emitter and broadcast-queue suites pass. Ruff check/format and targeted MyPy pass on Python 3.12. These tests use real Python mixer/frame objects; no LiveKit server or native FFI was needed. Two additional regression cases cover concurrent readers under immediate close and natural exhaustion; both fail before the review fix. Live call and cross-platform integration tests were not run.

Prepared with AI assistance and reproduced locally.

devin-ai-integration[bot]

This comment was marked as resolved.

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.

1 participant