Skip to content

fix(rtc): keep pending read when AudioMixer stream times out - #736

Closed
RaphaelFakhri wants to merge 1 commit into
livekit:mainfrom
RaphaelFakhri:fix/audio-mixer-read-timeout
Closed

RaphaelFakhri wants to merge 1 commit into
livekit:mainfrom
RaphaelFakhri:fix/audio-mixer-read-timeout

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Description

AudioMixer races each iterator.next() against streamTimeoutMs. On a timeout it moves on, and the next pass calls next() again. The first read is still pending, so the frame it later resolves with has no consumer and is dropped. Every timeout leaves another abandoned read, so audio that resumes after a silent period loses its first frames.

This change stores the pending read per stream and awaits it again on the next pass instead of starting a new one. The entry is cleared when the read settles, when the read rejects, and in removeStream.

Testing

Added does not drop a frame that arrives after a read timeout to audio_mixer.test.ts. It feeds a stream whose first frame arrives after the read timeout and expects both frames to come out of the mixer.

  • Without the change: 8 passed, 1 failed (received [], expected [111, 222]).
  • With the change: 9 passed.

Command: pnpm prebuild && npx vitest run src/audio_mixer.test.ts in packages/livekit-rtc.

A patch changeset for @livekit/rtc-node is included.

@changeset-bot

changeset-bot Bot commented Sep 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dc78d58

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

@CLAassistant

CLAassistant commented Sep 29, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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: 1 flag

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

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.

2 participants