Skip to content

fix(livekit): treat a negative ADM device count as zero devices - #1472

Closed
RaphaelFakhri wants to merge 2 commits into
livekit:mainfrom
RaphaelFakhri:fix/platform-audio-negative-device-count
Closed

RaphaelFakhri wants to merge 2 commits into
livekit:mainfrom
RaphaelFakhri:fix/platform-audio-negative-device-count

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Summary

PlatformAudio::recording_devices() and playout_devices() iterate over usize::MAX indices when the audio device module reports a negative device count.

The module returns a negative value (-1) when it is not initialized or fails to enumerate. recording_device_count() and playout_device_count() cast that i16 to usize, which wraps to 18446744073709551615. The iterator then walks every index at 100% CPU. This is the symptom described in #1468, where the platform ADM is left uninitialized after the last peer connection is released.

Changes

  • Add device_count, which maps a negative count to zero, and use it for both counts.
  • Add unit tests for negative and non-negative counts.
  • Add a livekit patch changeset.

This does not change the cause of the negative count in #1468. It makes the API return no devices instead of spinning.

Testing

cargo test -p livekit --lib device_count

  • Before the fix, negative_device_count_is_zero fails (1 passed, 1 failed).
  • After the fix, both tests pass (2 passed).
  • cargo fmt -p livekit -- --check reports no changes.

@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