Skip to content

fix(rtc-node): keep a late AudioMixer frame instead of skipping it - #781

Open
ANDROIDHASSAN wants to merge 1 commit into
livekit:mainfrom
ANDROIDHASSAN:fix/mixer-keep-timed-out-read
Open

ANDROIDHASSAN wants to merge 1 commit into
livekit:mainfrom
ANDROIDHASSAN:fix/mixer-keep-timed-out-read

Conversation

@ANDROIDHASSAN

Copy link
Copy Markdown
Contributor

Problem: AudioMixer.getContribution() races iterator.next() against streamTimeoutMs. When the timeout wins, the pending next() is left behind, and the next round calls iterator.next() again. The abandoned read still resolves with the stream's next frame, but nothing awaits it, so that frame is dropped. While the stream stays late, every round leaves another abandoned next() queued on the generator, and each one takes a later frame with it. With streamTimeoutMs: 10, a 5-frame stream whose third frame is 50 ms late reaches the output with 2 frames (960 of 2400 samples) and the warning is the only sign of it.

Fix: A read that times out is kept in pendingReads and awaited again in the next round instead of starting a new next(). removeStream() drops it. Timeouts still log the same warning and pad that round with silence, as before.

Tests: keeps the frames of a stream that was late once in audio_mixer.test.ts mixes the stream above and counts the samples that come out. On main it fails: expected 960 to be 2400. With the fix it passes (5 runs in a row). vitest run src in packages/livekit-rtc: 67 passed. The two e2e files fail to load here without a built livekit-server-sdk, on main too. ESLint: 0 errors, the same 11 warnings as main. tsc --noEmit reports only that e2e import. Prettier is clean. A @livekit/rtc-node patch changeset is included.

Scope: #736 tried this earlier and was closed by its author without review. The Python mixer got the same fix in livekit/python-sdks#862.

A read that loses the streamTimeoutMs race is now awaited again next round instead of being abandoned for a new next(), which dropped the frame it resolved with.
@changeset-bot

changeset-bot Bot commented Nov 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 11fdb10

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@livekit/rtc-node Patch

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

@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

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