From 8c602ddba1fd36178d2ca8cb01fcaca4efdc7687 Mon Sep 17 00:00:00 2001 From: Shivanshu Date: Mon, 3 Aug 2026 16:50:03 +0530 Subject: [PATCH 1/2] Fix: only latch WebRTC initialization after PeerConnectionFactory.initialize succeeds If PeerConnectionFactory.initialize throws (e.g. the native library fails to dlopen on a corrupted/partial install), hasInitializedWebrtc was already set to true, so every subsequent LiveKit.create() in the process skipped initialization and crashed at the first native call (ExternalAudioProcessingFactory.nativeGetDefaultApm) with an UnsatisfiedLinkError that cannot be caught as an Exception. Setting the latch only after initialize returns keeps failed initialization retryable and surfaces the underlying load failure as a catchable exception at the call site on every attempt. --- .../src/main/java/io/livekit/android/dagger/RTCModule.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/livekit-android-sdk/src/main/java/io/livekit/android/dagger/RTCModule.kt b/livekit-android-sdk/src/main/java/io/livekit/android/dagger/RTCModule.kt index e8d78fa43..2a0591a96 100644 --- a/livekit-android-sdk/src/main/java/io/livekit/android/dagger/RTCModule.kt +++ b/livekit-android-sdk/src/main/java/io/livekit/android/dagger/RTCModule.kt @@ -103,7 +103,6 @@ internal object RTCModule { if (!hasInitializedWebrtc) { executeBlockingOnRTCThread(LibWebrtcInitializationThreadToken) { if (!hasInitializedWebrtc) { - hasInitializedWebrtc = true PeerConnectionFactory.initialize( PeerConnectionFactory.InitializationOptions .builder(appContext) @@ -128,6 +127,12 @@ internal object RTCModule { ) .createInitializationOptions(), ) + // Only latch after initialize succeeds. If it throws (e.g. the native + // library fails to load), latching beforehand would permanently skip + // initialization for the process, and the next native call would crash + // with an uncatchable-by-catch(Exception) UnsatisfiedLinkError instead + // of a catchable failure at the call site. + hasInitializedWebrtc = true } } } From 22fa35bd4310f01403fd621872f41ebcef369978 Mon Sep 17 00:00:00 2001 From: Shivanshu Date: Mon, 3 Aug 2026 22:21:52 +0530 Subject: [PATCH 2/2] Add changeset --- .changeset/webrtc-init-latch-after-success.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/webrtc-init-latch-after-success.md diff --git a/.changeset/webrtc-init-latch-after-success.md b/.changeset/webrtc-init-latch-after-success.md new file mode 100644 index 000000000..192bfe1c2 --- /dev/null +++ b/.changeset/webrtc-init-latch-after-success.md @@ -0,0 +1,5 @@ +--- +"client-sdk-android": patch +--- + +Fix: only latch WebRTC initialization after PeerConnectionFactory.initialize succeeds, so a failed native library load stays retryable and surfaces as a catchable exception instead of poisoning the process and crashing on the next LiveKit.create() call.