Status Update
Comments
cc...@google.com <cc...@google.com> #2
reemission of the same liveData is racy
cc...@google.com <cc...@google.com> #4
ap...@google.com <ap...@google.com> #5
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
ju...@google.com <ju...@google.com> #6
na...@google.com <na...@google.com> #7
I actually have a WIP fix for it:
if your case is the one i found (emitting same LiveData multiple times, as shown in #5) you can work around it by adding a dummy transformation.
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData.map {it })
emitSource(subLiveData.map {it} )
}
ge...@gmail.com <ge...@gmail.com> #8
Branch: androidx-master-dev
commit af12e75e6b4110f48e44ca121466943909de8f06
Author: Yigit Boyar <yboyar@google.com>
Date: Tue Sep 03 12:58:11 2019
Fix coroutine livedata race condition
This CL fixes a bug in liveData builder where emitting same
LiveData source twice would make it crash because the second
emission registry could possibly happen before first one is
removed as source.
We fix it by using a suspending dispose function. It does feel
a bit hacky but we cannot make DisposableHandle.dispose async
and we do not want to block there. This does not mean that there
is a problem if developer disposes it manually since our emit
functions take care of making sure it disposes (and there is
no other way to add source to the underlying MediatorLiveData)
Bug: 140249349
Test: BuildLiveDataTest#raceTest_*
Change-Id: I0b464c242a583da4669af195cf2504e2adc4de40
M lifecycle/lifecycle-livedata-ktx/api/2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/current.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_current.txt
M lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/CoroutineLiveData.kt
M lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/BuildLiveDataTest.kt
da...@emirates.com <da...@emirates.com> #10
di...@okcredit.in <di...@okcredit.in> #11
cc...@google.com <cc...@google.com> #12
Note that we added extra debugging logging here in benchmark 1.3 though that doesn't change behavior, just added clarification and debugging steps:
If you still see this problem with profileinstaller 1.3.1, please try the following steps:
-
open your target (app) apk in studio and look for the
androidx.profileinstaller.ProfileInstallReceiver
to be present and unobfuscated in both your application manifest as a receiver, and in your dex -
when your target app is installed, try running
adb shell am broadcast -a androidx.profileinstaller.action.BENCHMARK_OPERATION -e DROP_SHADER_CACHE <yourapppackage>/androidx.profileinstaller.ProfileInstallReceiver
- it should print '14' as a response code if it's in your app and working correctly.
ke...@netflix.com <ke...@netflix.com> #13
I've verified that ProfileInstallReceiver is in the app's -benchmark.apk as well as the manifest. See screenshots.
Running the adb command also returns this:
% adb shell am broadcast -a androidx.profileinstaller.action.BENCHMARK_OPERATION -e EXTRA_BENCHMARK_OPERATION DROP_SHADER_CACHE com.netflix.mediaclient/androidx.profileinstaller.ProfileInstallReceiver
Broadcasting: Intent { act=androidx.profileinstaller.action.BENCHMARK_OPERATION flg=0x400000 cmp=com.netflix.mediaclient/androidx.profileinstaller.ProfileInstallReceiver (has extras) }
Broadcast completed: result=0
cc...@google.com <cc...@google.com> #14
Would also appreciate if you can try on different devices/emulators, and see if it works on some of them - I'm wondering if there's a device-specific issue you're hitting
On my Pixel6 Pro running Android 15 (API 35), running production Netflix (versionName=8.141.0 build 10 51376
), I see the command works as expected:
adb shell am broadcast -a androidx.profileinstaller.action.BENCHMARK_OPERATION -e EXTRA_BENCHMARK_OPERATION DROP_SHADER_CACHE com.netflix.mediaclient/androidx.profileinstaller.ProfileInstallReceiver
Broadcasting: Intent { act=androidx.profileinstaller.action.BENCHMARK_OPERATION flg=0x400000 cmp=com.netflix.mediaclient/androidx.profileinstaller.ProfileInstallReceiver (has extras) }
Broadcast completed: result=14
Description
Component used: Macrobench 1.2.0-alpha06, profileInstaller 1.3.0-alpha02
Devices/Android versions reproduced on: Pixel 7 API 33 user build
Running macrobenchmarks with the latest alpha versions is not possible on user builds due to (reproduced in Now In Android and Macrobenchmark samples)