Fix: only latch WebRTC initialization after PeerConnectionFactory.initialize succeeds - #992
Open
shivanshu877 wants to merge 2 commits into
Open
Fix: only latch WebRTC initialization after PeerConnectionFactory.initialize succeeds#992shivanshu877 wants to merge 2 commits into
shivanshu877 wants to merge 2 commits into
Conversation
…tialize 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.
shivanshu877
requested review from
MaxHeimbrock,
davidliu and
xianshijing-lk
as code owners
August 3, 2026 11:23
🦋 Changeset detectedLatest commit: 22fa35b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
davidliu
approved these changes
Aug 3, 2026
davidliu
left a comment
Contributor
There was a problem hiding this comment.
LGTM, can you sign the CLA and add a changeset? Instructions are found here:
https://github.com/livekit/client-sdk-android/blob/main/CONTRIBUTING.md
Author
|
Done — changeset added and CLA signed. All checks are green; ready for merge. Thanks for the quick review! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
RTCModule.libWebrtcInitializationsetshasInitializedWebrtc = truebefore callingPeerConnectionFactory.initialize(...). If initialization throws — most commonly when the native library fails to dlopen on a corrupted or partial install (missing arm64 split from sideloaded APKs, app cloners, broken Play delivery; see #572 for the same underlying load failure) — the latch stays set for the lifetime of the process.The first
LiveKit.create()then fails with a catchable exception (executeBlockingOnRTCThreadruns the block viaexecutor.submit(...).get(), so theUnsatisfiedLinkErrorsurfaces wrapped inExecutionException). Apps that catch it and later retry hit the poisoned latch: the secondLiveKit.create()skips initialization entirely and crashes at the first native call in the Dagger graph:Because this second failure is a raw
Erroron the caller's thread (not wrapped by aFuture), typicalcatch (Exception)handling cannot intercept it and the app process dies. We see this pattern in production via Crashlytics.Fix
Set
hasInitializedWebrtc = trueonly afterPeerConnectionFactory.initializereturns. A failed initialization stays retryable (webrtc's ownNativeLibrary.libraryLoadedalso remains false whenloadLibrarythrows, so a retry genuinely re-attempts the load), and every failed attempt surfaces as a catchable exception at theLiveKit.create()call site instead of a fatal, uncatchable crash on the second call.Notes
System.loadLibrary("lkjingle_peerconnection_so")fail (e.g. temporarily rename the lib in a test build), callLiveKit.create()twice in one process catchingExceptionaround each call. Before this change: first call throwsExecutionException, second call dies with theUnsatisfiedLinkErrorabove. After: both calls throw catchably.🤖 Generated with Claude Code