You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Build on LiveKit's official C++ SDK 1.13.1; fix the crash on quit on Windows - #17
This moves the build onto LiveKit's official C++ SDK (1.13.1) and fixes a crash on quit on Windows. Two commits:
1. Build on the official C++ SDK 1.13.1. Linux, Windows and macOS download the official releases (livekit/client-sdk-cpp, which ships every week or two) instead of the 0.3.1 fork. The code changes are the SDK's API changes:
the weak-pointer accessors (localParticipant, remote participants, e2eeManager, keyProvider);
publishTrack() now returns nothing and throws, so the publication comes from the track, and an error is reported instead of crashing.
On Windows, against the 0.3.1 fork, capture_frame on an audio source stalled the calling thread (a game dropped to about 20 fps), and subscriptions were sometimes lost. Both went away on 1.13.1.
2. Windows: pin LiveKit's DLLs. LiveKit's runtime threads outlive livekit::shutdown(). When Godot unloads the extension at exit, Windows unmaps livekit_ffi.dll and livekit.dll while those threads still run their code, so every process that had subscribed to a track crashed on quit. The extension now pins those DLLs and itself with GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN) at initialization, so they stay loaded until the process ends. Linux keeps such libraries mapped anyway.
Android needs your call. LiveKit publishes no Android build of the C++ SDK. So Android still downloads the fork's 0.3.1, which doesn't compile against the new API: no member named 'connect', roomInfo, lock. Some ways forward:
update the fork to 1.13 for Android;
build the official SDK for Android in CI;
or keep Android on the old code behind a version check.
Happy to do whichever you prefer, or to split the Windows fix into its own PR if that's easier to take first.
Testing
Your Build and Test workflow, run on my fork with fail-fast: false so every job finishes: Linux, Windows, macOS x86_64, macOS arm64 and Web pass; Android fails as above.
We also use this patch in a game (Godot 4.7.2). On Windows and Linux CI runners, against a local livekit-server 1.13: two clients publishing mic audio and a generated video track, subscribing to each other, then quitting (with and without leaving the room first), and leaving and rejoining. Every process exited with code 0.
On a 2-core laptop, one client receiving 7 people's audio and video held 60 fps.
Echo cancellation (LiveKitAudioProcessingModule), tested offline: it removed about 66 dB of a synthetic echo.
The build used a fork of the C++ SDK at 0.3.1. Move Linux, Windows and
macOS onto the official releases (1.13.1), which ship every week or two,
and adapt to their API: connect(), weak_ptr accessors (localParticipant,
remoteParticipants, e2eeManager, keyProvider), roomInfo(),
numChannels()/sampleRate(), streamState(). publishTrack() now returns
nothing and throws, so the publication is read from the track and an
error is reported instead of crashing.
On Windows, against the 0.3.1 fork, sending audio stalled the caller and
subscriptions were sometimes lost; both went away on 1.13.1.
LiveKit publishes no Android build of the C++ SDK, so Android stays on
the fork's 0.3.1 for now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PKkspXDoVPkiLYskHdfRWX
LiveKit's runtime threads outlive livekit::shutdown(). When Godot unloads
the extension at exit, Windows unmaps livekit_ffi.dll and livekit.dll
while those threads still run their code, and the process crashes on
quit (every process that had subscribed to a track). Pin the DLLs and
this module with GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN) at
initialization, so they stay mapped until the process ends. Linux keeps
such libraries mapped anyway.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PKkspXDoVPkiLYskHdfRWX
Thanks for this, it's great to be on the official SDK! We ran the native test suites against it on Linux, with the E2EE tests un-pended (1.13.1 fixes the crash on connect that pended them), and found a few problems with how the official SDK's objects are held:
Participants and E2EE objects can be used after they're freed. 1.x hands out the local participant, remote participants, the E2EE manager and its key provider as weak_ptrs, and frees them when a participant leaves or the room disconnects. .lock().get() keeps raw pointers to them, so a game that keeps one (e.g. the participant from participant_disconnected) reads freed memory. In our tests, its getters still returned the old identity, only because the memory hadn't been reused yet.
Tracks you don't keep a reference to drop out of get_track_publications(). The SDK only holds published tracks weakly, and once one is freed it forgets the publication, but leaves the track published. So publish_track(LiveKitLocalAudioTrack.create(...), {}) leaves a publication the server still sees, but that the game can no longer see or unpublish. test_video_flows_unencrypted_once_encryption_is_turned_off fails because of this once it's un-pended.
SDK calls throw while a room is disconnecting, which aborts the game. E.g. publish_data() right after disconnect_from_room() terminates with std::runtime_error.
LiveKitFrameCryptor.set_key_index() and set_enabled() abort the process. That's an SDK bug: its FrameCryptor doesn't send the track sid that the FFI requires, so the FFI panics on an unwrap(). We're filing it upstream with a fix.
We have a commit ready that fixes these (built on top of your branch). It:
keeps those objects as weak_ptrs, so a stale one reports "not bound" and its getters return empty values;
has the local participant keep its published tracks until they're unpublished;
reports SDK exceptions with push_error();
makes the frame cryptor setters fail with an error until the SDK fix ships, and keeps the 4 E2EE tests that need them pending;
adds native tests for each of these.
With it, the native suites pass on Linux: 194 tests, plus the 4 pending ones. (One other failure is from building without screen capture locally.)
Would you mind if we pushed it to this PR's branch? Or, if you'd rather, we can send it as a PR to your fork, or open a follow-up PR once this one's merged.
Written with Claude Opus 5.5 (an AI model by Anthropic), working with @mdepinet.
client-sdk-cpp 1.x hands out participants, the E2EE manager and its key
provider as weak_ptrs, and frees them when a participant leaves or the
room disconnects. Keep them weak in the wrappers, rather than as raw
pointers, so that objects a game keeps report "not bound" instead of
reading freed memory.
The SDK also only holds published tracks weakly, and forgets a freed
track's publication while leaving it published. So the local participant
now keeps its published tracks until they're unpublished.
SDK calls throw while a room is disconnecting, which aborted the game.
They're now reported with push_error(). FrameCryptor's setters abort the
process in 1.13.1 (they don't send the track sid the FFI requires), so
they fail with an error until the SDK is fixed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Thanks for testing it so thoroughly. Yes, please push it to this branch (maintainer edits are on). Once it's there we'll rebuild it into our game and rerun our Windows checks: two clients publishing and subscribing, then quitting, leaving and rejoining. We'll report back here.
Android is still open: do you want the fork updated to 1.13, the official SDK built for Android in CI, or Android kept on the old code for now? We're happy to do whichever you pick.
Thanks! The fix is pushed (cc56be5). Looking forward to hearing how your Windows checks go.
For Android, we'll take it on: we'd like to build the official SDK for Android in CI rather than keep a fork. LiveKit's Rust SDK already ships Android builds of livekit_ffi, and client-sdk-cpp can cross-compile, so it looks like a small amount of build plumbing. We'll prototype it and push it to this branch, so the PR doesn't leave Android behind. We'll also ask LiveKit whether they'd take Android support upstream, so that future SDK updates don't need it.
Written with Claude Opus 5.5 (an AI model by Anthropic), working with @mdepinet.
One thing from reading cc56be5 before we test: get_identity() now returns "" once the SDK has freed the participant. The room's signals are emitted after the SDK event, so a participant_disconnected or track_unsubscribed handler often gets a participant that's already freed. It then can't tell whose track it was, which is how a game knows which stream to drop. Our build saves the identity when the participant is bound, for this reason.
Could the wrapper keep identity, which never changes for a participant, and return it even when it's no longer bound, while everything else reports "not bound"? test_native_lifetimes.gd would then expect the old identity rather than "". Happy to push that change if you'd like.
Setup: a windows-2025 runner, Godot 4.7.2, livekit-server 1.13.11, two headless clients publishing mic audio and a VP8 video track (run, workflow).
20 s, audio pushed from a worker thread, then disconnect and quit: both clients subscribed to each other's audio and video within 0.35 s, and both exited with code 0.
Leave at 6 s, rejoin 2 s later, then quit without disconnecting: both resubscribed within 0.2 s of rejoining, and both exited with code 0.
For comparison, I ran the same check on the build we ship now (1c98e2a with our 1.13 patch; run). Frame rate and the time spent pushing audio are the same. The local_track_subscribed for unknown sid warnings we had are gone with your commit. Both builds log failed to negotiate the publisher ... Called in wrong state from the Rust SDK when disconnecting, so that isn't new.
These checks don't cover a remote participant leaving while the other stays, so they don't test the identity question above.
Handlers for a participant leaving, e.g. participant_disconnected, often
run after the SDK has freed it, and still need to know who left. The
identity never changes, so the wrapper keeps the one it was bound with,
while everything else still reports "not bound".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LiveKit publishes no Android build of client-sdk-cpp, and the fork's
0.3.1 build doesn't match the official SDK's API. So on a cache miss,
build.sh now builds v1.13.1 for Android arm64 from LiveKit's release,
with patches/client-sdk-cpp-android.patch for cross-compiling with the
NDK, and caches it with a key that includes the patch.
That needs NDK r27 (r26d's libc++ can't build webrtc-sys), plus git,
CMake, Ninja and Rust, so CI moves to r27d, installs Ninja, and caches
livekit-sdk. On Android the FFI uses the bundled webpki roots, as
LiveKit's own Android FFI builds do, and the SDK's HTTP token sources
aren't available (they need libcurl).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SDK reports errors by throwing, but with the NDK's default static
C++ runtime, liblivekit and the extension each had their own copy, so the
extension's catch blocks never matched and the app aborted instead (found
running the test suites on an emulator). Building the SDK with
c++_shared makes both use the libc++_shared.so the app already ships.
The patch also picks up the upstream proposal's warning for static
runtimes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Thanks for the Windows results, and for catching the identity problem!
Identity (5f499cc): done as you suggested. A participant keeps the identity it was bound with, and everything else still reports "not bound". test_native_lifetimes.gd now expects the old identity.
Android (cbf207f, ba0e9bd):build.sh android now builds LiveKit's official v1.13.1 for Android, so the fork is no longer used. It applies a small build patch kept in patches/, and CI caches the result. The first, uncached CI run took about 14 minutes. Notes:
It needs NDK r27, since the current Rust SDK doesn't build with r26d. Both workflows now use r27d.
The SDK is built with the shared C++ runtime. With the NDK's default static runtime, the extension couldn't catch the SDK's exceptions, and the app aborted instead.
On Android, the SDK uses the CA certificates bundled with it, as LiveKit's own Android builds do. Its default certificate lookup doesn't find Android's.
The SDK's HTTP token sources aren't available on Android, since they need libcurl. The plugin doesn't use them.
We ran the unit, integration and e2e suites on an Android 14 emulator against a local LiveKit server, using an x86_64 build of the same code. Everything passed, apart from:
The screen-capture class check, since Android builds don't include screen capture.
Three E2EE tests that tripped the existing lock contention warning, which also flakes on Linux.
We're also proposing the Android build support upstream, so future SDK updates won't need the patch.
Written with Claude Opus 5.5 (an AI model by Anthropic), working with @mdepinet.
The reader threads hold the lock only briefly and keep what they read
for the next poll, so a single skipped poll is harmless. Warning on the
first one made tests that check for unexpected warnings fail at random
(three E2EE tests on an Android emulator). The quickstart already
describes the warning as appearing when contention happens repeatedly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Android builds leave out LiveKitScreenCapture, so scripts that use it
don't compile there, and GUT skips them without failing. That hid all
of test_threading_stress.gd on Android, so its screen capture tests
move to their own file. The registration check no longer expects the
class on Android.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The new job builds for Android x86_64 (which GitHub's runners can
emulate at a usable speed), exports a test app with Godot's Gradle
build, and runs the unit, integration and e2e suites on an Android 14
emulator against a local livekit-server. test_android.sh does the
export and run, and works with any device or emulator on adb.
- build.sh and SConstruct take `android x86_64`, and the Android build
keeps the SDK build's libwebrtc.jar, which apps need. The godot-cpp
cache check now notices a build for another architecture.
- The project enables ETC2/ASTC import, which Android exports require.
- Join tokens for the integration tests come from test/dev_token.py,
shared with the web job.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Android, encrypted video sometimes never starts: the subscriber gets
every packet but decodes none and never asks for a keyframe (NodotProject#19). The
three tests that need it to start as soon as the rooms connect are
pending there until the cause is found and fixed upstream.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every LiveKitAudioStream zero-filled a 1.9 MB ring buffer in its
constructor, though only streams made from a track or participant use
it. On an Android emulator, that made test_audio_stream_immediate_gc's
50 bare streams exceed its 500 ms budget.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ilt for
livekit_android_jni_init always loaded godot-livekit.android.arm64, so
on x86_64 the call failed (logging an error) and the AV1 stubs weren't
registered.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
We've added an Android emulator job to CI, so the Android build is now tested on every run, not just built:
CI (ecf18f4): the new job builds for Android x86_64 (GitHub's runners can only emulate their own architecture at a usable speed), exports a test app with Godot's Gradle build, and runs the unit, integration and e2e suites on an Android 14 emulator against a local livekit-server. test_android.sh does the export and run, and works with any device or emulator on adb. A cached run takes about 10 minutes.
Tests (a5c3f75): Android builds leave out screen capture, so test scripts that use it don't compile there, and GUT skips them without failing. That had hidden all of test_threading_stress.gd on Android, so its screen capture tests now have their own file. test_android.sh fails if any test script doesn't compile.
Lock contention warning (a043d5e): it now fires only when contention keeps happening, as the quickstart describes. It used to fire on the first skipped poll, which made tests that check for unexpected warnings fail at random.
Audio stream memory (be2e1cf): every LiveKitAudioStream zero-filled a 1.9 MB buffer when created, even ones that never read. It's now allocated when a stream starts reading, which also brought a stress test of 50 bare streams back under its time budget on the emulator.
Android x86_64 (5f35721): the extension always Java-loaded its arm64 library by name, so on x86_64 that failed with an error and the AV1 stubs weren't registered. It now loads the library for the architecture it was built for.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The Android test script can permanently delete an existing android/ directory, including custom build files, plugins, and keystores, without restoring it.
Migrates the Godot extension to LiveKit’s official C++ SDK 1.13.1 and addresses Windows shutdown crashes. The changes also add a patched Android SDK source build and emulator-based testing.
Changes:
Updates native SDK calls, object lifetimes, and exception handling.
Pins Windows modules to prevent unloading while LiveKit threads remain active.
Adds Android x86_64 support, test tooling, and lifecycle regression coverage.
File
Description
test/unit/test_threading_stress.gd
Moves screen-capture tests into a separate suite.
test/unit/test_screen_capture_threading.gd
Holds screen-capture threading tests.
test/unit/test_platform.gd
Adjusts Android class-registration expectations.
test/e2e/test_track_lifecycle.gd
Tests publication lifetime without retained track wrappers.
test/e2e/test_native_lifetimes.gd
Tests native wrappers after disconnection.
test/e2e/test_e2ee.gd
Enables native encryption tests with targeted skips.
test/dev_token.py
Generates development-server join tokens.
test/android/android_runner.tscn
Adds the Android test-runner scene.
test/android/android_runner.gd
Runs selected tests and reports Android results.
test_android.sh
Exports, installs, and runs Android tests.
src/windows_pin.h
Declares Windows module pinning.
src/windows_pin.cpp
Keeps extension and LiveKit DLLs loaded until process exit.
src/web/README.md
Clarifies native participant behavior after disconnection.
src/sdk_call.h
Converts SDK exceptions into Godot errors.
src/register_types.cpp
Pins Windows modules during initialization.
src/livekit_video_stream.cpp
Retains participants during stream creation; reduces warnings.
src/livekit_track.cpp
Uses the updated stream-state accessor.
src/livekit_room.h
Updates the connection-timeout comment.
src/livekit_room.cpp
Adapts room APIs and participant binding.
src/livekit_participant.h
Defines weak participant ownership and retained published tracks.
src/livekit_participant.cpp
Updates publishing, participant access, and exception handling.
src/livekit_e2ee.h
Uses weak references for encryption objects.
src/livekit_e2ee.cpp
Guards encryption calls and disables unsupported cryptor setters.
src/livekit_audio_stream.h
Documents deferred ring-buffer allocation.
src/livekit_audio_stream.cpp
Updates audio APIs and allocates buffers when reading starts.
src/android_jni_init.cpp
Loads the architecture-specific Android extension.
SConstruct
Adds Android x86_64 targeting and Windows pinning compilation.
README.md
Documents Android test prerequisites.
project.godot
Enables Android-compatible texture imports.
patches/client-sdk-cpp-android.patch
Adds Android cross-compilation support to the SDK.
build.sh
Uses official releases and builds the Android SDK from source.
addons/godot-livekit/godot-livekit.gdextension
Registers Android x86_64 libraries and dependencies.
.gitignore
Excludes SDK build artifacts and Android templates.
.github/workflows/build_release.yml
Updates Android prerequisites and dependency caching.
.github/workflows/build_and_test.yml
Adds Android emulator testing and shared token generation.
…hecks
- build.sh downloads the protoc for the build machine (Linux x86_64 or
arm64, or macOS), avoids nproc and sha256sum, and finds libwebrtc.jar in
CARGO_TARGET_DIR when it's set.
- test_android.sh only replaces an Android build template it installed,
and fails if the app doesn't exit after the tests.
- The unkept-track test asserts that the track gets published.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A CI run's app stopped about 15 seconds after launch, before the tests
started, and logcat's crash tags showed nothing. Also print whether the
app exited, what ActivityManager and lmkd logged about it, and Godot's
own logcat output.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The Android test runner can report success after a native shutdown crash because it trusts a pre-quit result marker without checking for abnormal termination.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Reject runs with native crashes during shutdown
test_android.sh:267
A native crash during shutdown can still be reported as a passing run: the runner prints GUT_ANDROID_RESULT before quit(), and app_exited only establishes that the process disappeared. Crash diagnostics are also skipped when the result marker exists. Check the app's exit reason or process-scoped crash records even when a marker is present, and reject abnormal termination before reporting success.
Re Copilot's "previously missed issue" (native crashes during shutdown in test_android.sh): fixed in 3dac22d. A run now also fails if Android's crash log has an entry for the app. The script clears that log before starting the app. We checked that a native crash in the app is caught this way.
Written with Claude Opus 5.5 (an AI model by Anthropic), working with @mdepinet.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Retained participant wrappers can keep native tracks alive after disconnect, while hard-coded timeout calls break Android testing on macOS systems using Homebrew’s gtimeout.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Release published tracks during teardown and reconnect
src/livekit_participant.h:65
If application code keeps a local participant after disconnect, this list retains all its published native tracks even after application track references are dropped. Room teardown only releases its reference to the wrapper, and unpublish_track() cannot clear the list once the native participant expires. Add a track-release hook and call it during connection teardown and reconnect, rather than retaining these resources until the stale wrapper is destroyed.
Use gtimeout fallback for macOS export commands
test_android.sh:207
On macOS, Homebrew coreutils provides gtimeout, not timeout, so this export fails with “command not found” even when the documented prerequisites are installed; --apk also fails at the hard-coded call on line 230. Please select timeout or gtimeout once and use that executable for all three calls, as test.sh:45–49 and test_web.sh already do.
Apps may keep the local participant after disconnecting, which kept the
tracks it published alive too. Also fall back to gtimeout in
test_android.sh, as the other test scripts do.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Re Copilot's two previously missed issues, both fixed in f7c5fca:
Published tracks after disconnecting: the room now has the local participant release its published tracks when the connection ends, on disconnect and on reconnect. So a participant an app keeps afterwards no longer keeps those tracks alive.
gtimeout on macOS:test_android.sh now uses gtimeout when timeout isn't available, as test.sh does.
Written with Claude Opus 5.5 (an AI model by Anthropic), working with @mdepinet.
Builds the extension on Windows and runs two Godot clients against a
local livekit-server: 20 s publishing and subscribing, then quitting; and
leaving and rejoining. Every client must exit with 0. Only on this
branch, to test PR NodotProject#17 on Windows; not meant for merging.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PKkspasfdkywV2cpgDmV6K
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because unpublished findings raise concerns about native-track retention after connection teardown and export-template discovery on macOS.
In retrospect, I probably should have merged your change as it was and then added the Android stuff separately. Sorry about that! Planning to land it all together after CI passes.
The SDK's local participant methods wait for a reply without a timeout,
and a room being torn down may not send one. An Android CI run hung in
the test that publishes data from a kept participant right after
disconnecting, so calls made after the connection ends now fail with
"not bound" instead of reaching the SDK.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On CI's emulator, the app has twice exited before Godot finished
starting, so before any of the plugin's tests ran. Relaunch it up to
twice when that happens, but not after a crash or once the tests have
started. When a run times out with the app still running, print every
thread's stack, which emulator images allow through root.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Clearing participant_ skips RPC handler unregistration, leaving callbacks with a raw this pointer that can access a freed Godot object during disconnect or reconnect cleanup.
…icipant
Unbinding stopped the destructor from unregistering them, and they held
the participant's raw pointer, so an RPC arriving during teardown could
reach a freed object. Unregister them when unbinding, and have handlers
hold only the participant's ID and emit from the main thread if it still
exists, since the SDK may still be running one when it's freed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed to evaluate unpublished findings involving macOS template-discovery failures and native-track retention after room destruction.
NodotProject#18's new data-only ratchet test called _skip_if_unsupported(), which this branch replaced with
per-test checks, so it uses _skip_if_no_server() now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_encryption_turned_off_and_on_again_stays_on failed about 1 run in 6, on Linux as well as
Android. Room 2 was failing to decrypt video with a wrong key, and WebRTC's frame cryptor puts back
the key it started a failed ratchet attempt with, even if set_shared_key() replaced it meanwhile. So
room 2 usually lost the right key within milliseconds, and the test only passed when its data message
got in first. The test is about encryption staying on, so room 2 now doesn't ratchet, like the tests
that recover from a wrong key.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The emulator job failed twice on CI, both times before any of the plugin's tests ran: Godot exited while still starting up, with no crash. Logs from the second failure show the emulator was still finishing its boot when that happened. I couldn't reproduce it locally, so the test script now relaunches an app that exits before the tests start, up to twice (3a4ff39). It doesn't relaunch after a crash or once the tests have started.
While testing that, a local run hung in test_local_participant_kept_after_disconnecting_is_unbound_but_keeps_its_identity. That test calls publish_data right after disconnecting. The SDK's local participant methods wait for a reply with no timeout, and a room being torn down might not send one. I couldn't reproduce the hang in 55 more runs, so that's the likely cause rather than a confirmed one. Either way:
9850d01: the room now unbinds its local participant when the connection ends, so later calls fail with "not bound" instead of reaching the SDK.
3a4ff39: if a run times out with the app still running, the script prints every thread's stack, so another hang would show where it's stuck.
Since then:
a0e3149: following Copilot's review, unbinding also removes the participant's RPC handlers, and handlers no longer hold the participant itself, so a late RPC can't reach a freed one.
9bfda9c merges main. Web: update livekit-client to 2.24.0 #18's new data-only ratchet test called _skip_if_unsupported(), which this PR replaces with per-test checks. The two merged without a conflict, but the result didn't parse, which made the last emulator run fail. The new test uses _skip_if_no_server() now and passes natively.
79774cf fixes a flaky test, test_encryption_turned_off_and_on_again_stays_on, which failed about 1 run in 6 on Linux as well as Android. When WebRTC's frame cryptor gives up ratcheting a key it can't decrypt with, it puts that key back, even if set_shared_key() replaced it meanwhile. The test's receiver now has a ratchet window of 0, like the tests that recover from a wrong key. That WebRTC bug is FrameCryptor: a failed ratchet attempt puts back the old key over one set while it ran livekit/libwebrtc#338.
Written with Claude Opus 5.5 (an AI model by Anthropic), working with @mdepinet.
Builds the extension on Windows and runs two Godot clients against a
local livekit-server: 20 s publishing and subscribing, then quitting; and
leaving and rejoining. Every client must exit with 0. Only on this
branch, to test PR NodotProject#17 on Windows; not meant for merging.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PKkspasfdkywV2cpgDmV6K
Windows results for the merged commit (6a395ec): all good.
I reran our three cases on it (run): two clients for 20 s with audio from a worker thread, leave and rejoin, and one client leaving at 6 s while the other stays. The client that stays gets the leaver's identity when both of its tracks unsubscribe, in participant_disconnected, and again a second later after the SDK has freed it. Every client exited with code 0, and they resubscribed within 0.2 s of rejoining. The Rust SDK's failed to negotiate the publisher ... Called in wrong state on disconnect is still there, as before.
No need to apologize about landing it together. Thanks for merging it and for keeping the identity. We'll move our build onto it and drop our patch.
A follow-up on the Windows results: on a slower machine (a 2-core laptop under load) the merged build sometimes crashes on quit. It happens when a client reconnects with the same LiveKitRoom (disconnect_from_room(), then connect_to_room() again) and then quits without disconnecting. Just before, livekit_ffi logs failed to handle request: InvalidRequest("handle is not a livekit_ffi::room_apis::server::room::FfiTrack") twice, and the process exits with 0xc0000409. It crashed in 2 of 4 runs and logged the error in 3 of them. Reconnecting and then disconnecting before quitting was clean (3 of 3), and so was quitting without disconnecting when there had been no reconnect (3 of 3). Our old build (1c98e2a with our patch) was clean in the failing case on the same machine (3 of 3). The GitHub runners didn't hit it.
To reproduce, from cubicle-check/ on our check branch: node tools/livekit-check/run.mjs --clients=2 --seconds=20 --shutdown=none --leave-at=6 --rejoin. We haven't tracked down the cause yet.
A correction to my crash-on-quit follow-up: with more runs, I don't think it's tied to 6a395ec.
I reran the failing case (run.mjs --clients=2 --seconds=20 --shutdown=none --leave-at=6 --rejoin) on the same laptop, alternating between the merged build and our old one (1c98e2a with our patch) so both saw the same load. Both used byte-identical livekit.dll and livekit_ffi.dll (1.13.1); only the extension DLL differed.
Crashes on quit:6a395ec 1 of 11, the old build 0 of 10. With the earlier runs that's 3 of 15 against 0 of 13, which chance alone gives about one time in seven.
The handle is not a ...FfiTrack error isn't new. The old build logs it too (5 of 10 runs, against 10 of 11 on 6a395ec). It comes from LiveKitTrack::request_stats around quit, so it isn't a sign of the crash the way I suggested.
So there is a rare crash on quit after reconnecting with the same LiveKitRoom and quitting without disconnecting, but these numbers can't tell whether 6a395ec made it more likely. Sorry for the noise. If we find a reliable repro we'll open an issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This moves the build onto LiveKit's official C++ SDK (1.13.1) and fixes a crash on quit on Windows. Two commits:
1. Build on the official C++ SDK 1.13.1. Linux, Windows and macOS download the official releases (
livekit/client-sdk-cpp, which ships every week or two) instead of the 0.3.1 fork. The code changes are the SDK's API changes:connect(),roomInfo(),numChannels()/sampleRate(),streamState();localParticipant, remote participants,e2eeManager,keyProvider);publishTrack()now returns nothing and throws, so the publication comes from the track, and an error is reported instead of crashing.On Windows, against the 0.3.1 fork,
capture_frameon an audio source stalled the calling thread (a game dropped to about 20 fps), and subscriptions were sometimes lost. Both went away on 1.13.1.2. Windows: pin LiveKit's DLLs. LiveKit's runtime threads outlive
livekit::shutdown(). When Godot unloads the extension at exit, Windows unmapslivekit_ffi.dllandlivekit.dllwhile those threads still run their code, so every process that had subscribed to a track crashed on quit. The extension now pins those DLLs and itself withGetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN)at initialization, so they stay loaded until the process ends. Linux keeps such libraries mapped anyway.Android needs your call. LiveKit publishes no Android build of the C++ SDK. So Android still downloads the fork's 0.3.1, which doesn't compile against the new API:
no member named 'connect',roomInfo,lock. Some ways forward:Happy to do whichever you prefer, or to split the Windows fix into its own PR if that's easier to take first.
Testing
fail-fast: falseso every job finishes: Linux, Windows, macOS x86_64, macOS arm64 and Web pass; Android fails as above.LiveKitAudioProcessingModule), tested offline: it removed about 66 dB of a synthetic echo.🤖 Generated with Claude Code
https://claude.ai/code/session_01PKkspXDoVPkiLYskHdfRWX