Skip to content

fix: dispose native handles on audio/video stream EOS#637

Open
LautaroPetaccio wants to merge 3 commits intolivekit:mainfrom
LautaroPetaccio:fix/dispose-stream-handles-on-eos
Open

fix: dispose native handles on audio/video stream EOS#637
LautaroPetaccio wants to merge 3 commits intolivekit:mainfrom
LautaroPetaccio:fix/dispose-stream-handles-on-eos

Conversation

@LautaroPetaccio
Copy link
Copy Markdown

Why

AudioStreamSource and VideoStreamSource create an FfiHandle for the native stream. On eos (end-of-stream), they removed the event listener and closed the controller but never called ffiHandle.dispose(). The handle was only disposed in the cancel() path. Streams that end normally (the common case) leaked the native handle.

Additionally, AudioStreamSource.cancel() did not close the frameProcessor, so cancelling a noise-cancelled audio stream leaked the processor resource.

How

  • In the eos case of both AudioStreamSource.onEvent and VideoStreamSource.onEvent, add this.ffiHandle.dispose() after closing the controller. This makes the EOS path symmetric with the cancel() path.
  • Add this.frameProcessor?.close() to AudioStreamSource.cancel() so both termination paths release the processor.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 1, 2026

🦋 Changeset detected

Latest commit: 670293c

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

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot left a comment

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 potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

devin-ai-integration[bot]

This comment was marked as resolved.

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