Fixed
Status Update
Comments
jb...@google.com <jb...@google.com>
jb...@google.com <jb...@google.com>
tp...@gmail.com <tp...@gmail.com> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
jb...@google.com <jb...@google.com> #3
yea i'll take it.
ap...@google.com <ap...@google.com> #4
Thanks for the detailed analysis. This may not be an issue anymore since we've started using Main.immediate there but I' not sure; I'll try to create a test case.
jb...@google.com <jb...@google.com> #5
just emitting same live data reproduces the issue.
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
jb...@google.com <jb...@google.com> #6
With 2.2.0-alpha04 (that use Main.immediate), the issue seems to be still there (I tested it by calling emitSource() twice, like your test case)
tp...@gmail.com <tp...@gmail.com> #7
yea sorry immediate does not fix it.
I actually have a WIP fix for it:
https://android-review.googlesource.com/c/platform/frameworks/support/+/1112186
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} )
}
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} )
}
ma...@gmail.com <ma...@gmail.com> #8
Project: platform/frameworks/support
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
https://android-review.googlesource.com/1112186
https://goto.google.com/android-sha1/af12e75e6b4110f48e44ca121466943909de8f06
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
na...@google.com <na...@google.com> #9
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.fragment:fragment:1.6.0-rc01
za...@google.com <za...@google.com> #10
Still hitting this: YAQS/8332979824100376576
ma...@zentity.com <ma...@zentity.com> #11
Still persist in 2.6.0. From Crashlytics report:
Fatal Exception: java.lang.IllegalArgumentException: The fragment MyFragment{e08e9e3} (ffd3a63d-e7c5-4d27-8836-9579f2aea852 id=0x7f0a03a2 tag=0dcc6840-37be-40d3-9aab-10a5381ca884) is unknown to the FragmentNavigator. Please use the navigate() function to add fragments to the FragmentNavigator managed FragmentManager.
at androidx.navigation.fragment.FragmentNavigator$onAttach$2.onBackStackChangeCommitted(FragmentNavigator.kt:143)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1918)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1845)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1782)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:565)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7879)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1009)
MyFragment is in main fragment for subgraph which is included to nav_graph.xml.
an...@gmail.com <an...@gmail.com> #12
Keeps occurring on version 2.6.0.
Same case as above so I assume that not further details are required.
All good if I test with version 2.6.0-alpha09.
I assume the problem starts here:https://developer.android.com/jetpack/androidx/releases/navigation#2.6.0-beta01 .
I do add fragments navigate() and there are no manual FragmentTransaction's in the project.
Same case as above so I assume that not further details are required.
All good if I test with version 2.6.0-alpha09.
I assume the problem starts here:
I do add fragments navigate() and there are no manual FragmentTransaction's in the project.
jb...@google.com <jb...@google.com> #13
Please file a new bug with a minimal sample project that reproduces this issue.
go...@gmail.com <go...@gmail.com> #14
I also have this problem, version 2.7.5
I have a BottomNavigationView and I just quickly click on two elements asynchronously and within 1 minute it crashes
You probably have test projects, two fragments will be enough
I have a BottomNavigationView and I just quickly click on two elements asynchronously and within 1 minute it crashes
You probably have test projects, two fragments will be enough
jb...@google.com <jb...@google.com> #15
We will need you to file a new bug with a minimal sample project that reproduces this issue.
Description
Version used: 2.6.0-beta01
Devices/Android versions reproduced on: Everywhere
Crash stack trace
java.lang.IllegalArgumentException: The fragment BottomSheetFragment{6c59aad}
(a05692b2-965c-40c6-82ce-57991ab0e8d6 tag=b3f6ebd6-263b-402f-8ebe-7762287c5f6d) is unknown to the FragmentNavigator. Please use the navigate() function to add fragments to the FragmentNavigator managed FragmentManager. (FragmentNavigator.kt:147)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1918)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1845)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1782)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:565)
You can reproduce crash in the attached project.
Project has 3 fragments.
1. StartFragment
2. BottomSheetDialog
3. SimpleFragment
Navigation flow looks like: StartFragment (click on button) -> Navigation opens BottomSheet dialog fragment (click on button) -> crash.
But in 2.6.0-alpha09 and below crash is not reproduced and all works fine (BottomSheet dialog disappears and SimpleFragment appears, back stack looks like StartFragment -> SimpleFragment)
Thanks.