Fixes exception when audioSwitch.stop() gets called before start()#943
Fixes exception when audioSwitch.stop() gets called before start()#943pulakdp wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 0324455 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 |
|
Hmm, AudioSwitch itself has its own state management which shouldn't call through to the underlying cleanup if it hasn't started yet. Simply calling stop() before start() does not result in a crash. The race condition you added by using reflection to change the state to STARTED in your test doesn't seem possible in production unless you're also using reflection to alter the inner state of AudioSwitch in production? |
|
I was not using reflection to alter states but at the same time I was not able to repro the issue. I saw a good number of crashes due to this specially on Vivo devices. However, I saw your PR davidliu/audioswitch#9 is a better fix directly at the site of exception. I'll try version |
On upgrade of livekit SDK from
2.24.0to2.25.2, I observed a fresh crash with the following stack trace:This happens because LiveKit now uses
CommDeviceAudioSwitchfor Android 12 and above which unconditionally callsremoveOnCommunicationDeviceChangedListener()without checking if the listener was ever registered. Sincestart()andstop()are called using same Handler, in some cases this leads to a race condition wherestart()is not yet called beforestop()executes leading to this crash. Added simple boolean guardrail to avoid this.I have added some tests which demonstrates the issue when guardrail is not there.