Skip to content

Explicitly drop FFI handles on dispose#1174

Open
alan-george-lk wants to merge 3 commits into
mainfrom
bugfix/ffi_handle_cleanup
Open

Explicitly drop FFI handles on dispose#1174
alan-george-lk wants to merge 3 commits into
mainfrom
bugfix/ffi_handle_cleanup

Conversation

@alan-george-lk

@alan-george-lk alan-george-lk commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Before you submit your PR

Make sure the following is true before submitting your PR:

  • I have read the contributing guidelines and validated that this PR will be accepted.
  • I have read and followed the principles regarding breaking changes, testing, and code quality.

PR description

This PR resolves an issue observed in the downstream C++ SDK during repeated unit/integration test runs, where the FFI handle state was not completely cleared and caused issues for different test cases intended to be atomic, but within the same process boundary. This specifically raised a crash in PlatformAudio tests.

Breaking changes

N/A

MSRV

If the PR modifies the crate's MSRV (Minimum Supported Rust Version), document it here.

Testing

Validated in a downstream C++ SDK run against this branch.

Async

We want the project to be runtime-agnostic, so please reuse what's already in livekit-runtime and feel free to add anything missing. It's ok to use Tokio directly, when writing unit tests, if necessary. When testing, do not use artificial delays for the state to "catch up"; instead, respect the event flow and subscribe properly using channels or other mechanisms.

@github-actions

Copy link
Copy Markdown
Contributor

Changeset

The following package versions will be affected by this PR:

Package Bump
livekit-ffi patch

Clear remaining FFI handles during dispose so owned native resources are released across repeated initialize/shutdown cycles.

Co-authored-by: Cursor <cursoragent@cursor.com>
@alan-george-lk alan-george-lk force-pushed the bugfix/ffi_handle_cleanup branch from 860b96d to 9209583 Compare June 16, 2026 22:44
@alan-george-lk alan-george-lk marked this pull request as ready for review June 16, 2026 22:45
Comment thread livekit-ffi/src/server/mod.rs
alan-george-lk and others added 2 commits June 16, 2026 16:55
Log PlatformAudio FFI handle lifecycle details so repeated shutdown/init runs can confirm whether handles are dropped before dispose or cleared during dispose.

Co-authored-by: Cursor <cursoragent@cursor.com>
.iter()
.filter(|handle| handle.value().is::<platform_audio::FfiPlatformAudio>())
.count();
log::debug!(

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.

unless we add an explicit API to shutdown the PlatformAudio, otherwise it is expected that some platform_audio_handles will remain valid here.

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.

4 participants