Fixed
Status Update
Comments
[Deleted User] <[Deleted User]> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
[Deleted User] <[Deleted User]> #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.
ap...@google.com <ap...@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()
}
}
ap...@google.com <ap...@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)
ap...@google.com <ap...@google.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} )
}
ap...@google.com <ap...@google.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
ap...@google.com <ap...@google.com> #9
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 5da219c2d359c9a9e339ccf206e0f6f51dfa6ab2
Author: Jeremy Woods <jbwoods@google.com>
Date: Fri Sep 20 15:46:21 2019
Fix androidx transitions for Fragments
We should ensure that both androidx and support transitions work in
conjuction with Fragments. This change moves the
setListenerForTransitionEnd() method to FragmentTransitionImpl, then
implements overrides for the FragmentTransitionCompat21 and
FragmentTransitionSupport classes, so the two types of transitions can
be handled separately.
Test: added FragmentTransitionTests in previous CL
BUG: 140680619
Change-Id: I6fdda6609d8fe91d9f8618510495180572262a5b
M fragment/fragment/api/restricted_1.2.0-alpha05.txt
M fragment/fragment/api/restricted_current.txt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentTransition.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentTransitionCompat21.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentTransitionImpl.java
M transition/transition/src/main/java/androidx/transition/FragmentTransitionSupport.java
https://android-review.googlesource.com/1119841
https://goto.google.com/android-sha1/5da219c2d359c9a9e339ccf206e0f6f51dfa6ab2
Branch: androidx-master-dev
commit 5da219c2d359c9a9e339ccf206e0f6f51dfa6ab2
Author: Jeremy Woods <jbwoods@google.com>
Date: Fri Sep 20 15:46:21 2019
Fix androidx transitions for Fragments
We should ensure that both androidx and support transitions work in
conjuction with Fragments. This change moves the
setListenerForTransitionEnd() method to FragmentTransitionImpl, then
implements overrides for the FragmentTransitionCompat21 and
FragmentTransitionSupport classes, so the two types of transitions can
be handled separately.
Test: added FragmentTransitionTests in previous CL
BUG: 140680619
Change-Id: I6fdda6609d8fe91d9f8618510495180572262a5b
M fragment/fragment/api/restricted_1.2.0-alpha05.txt
M fragment/fragment/api/restricted_current.txt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentTransition.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentTransitionCompat21.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentTransitionImpl.java
M transition/transition/src/main/java/androidx/transition/FragmentTransitionSupport.java
ap...@google.com <ap...@google.com> #10
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 366bb45ac5b9b06d1f6c9da0d94e825e093a4e7c
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Sep 16 13:29:48 2019
Add Fragment transition tests to androidx transitions
We should test fragment transitions for both androidx and support
transtions. This change copies over the transition tests from Fragments.
Test: this added tests
BUG: 140680619
Change-Id: I298535c1205686a75d205a65610af3fd43adeef8
M transition/transition/build.gradle
M transition/transition/src/androidTest/AndroidManifest.xml
A transition/transition/src/androidTest/java/androidx/transition/FragmentTestActivity.kt
A transition/transition/src/androidTest/java/androidx/transition/FragmentTestUtil.kt
M transition/transition/src/androidTest/java/androidx/transition/FragmentTransitionSupportTest.java
A transition/transition/src/androidTest/java/androidx/transition/FragmentTransitionTest.kt
A transition/transition/src/androidTest/java/androidx/transition/TrackingTransition.kt
A transition/transition/src/androidTest/java/androidx/transition/TrackingVisibility.java
A transition/transition/src/androidTest/java/androidx/transition/TransitionFragment.kt
A transition/transition/src/androidTest/res/layout/activity_content.xml
A transition/transition/src/androidTest/res/layout/double_container.xml
A transition/transition/src/androidTest/res/layout/fragment_scene1.xml
A transition/transition/src/androidTest/res/layout/fragment_scene2.xml
A transition/transition/src/androidTest/res/layout/fragment_scene3.xml
A transition/transition/src/androidTest/res/layout/simple_container.xml
A transition/transition/src/androidTest/res/layout/strict_view_fragment.xml
https://android-review.googlesource.com/1119840
https://goto.google.com/android-sha1/366bb45ac5b9b06d1f6c9da0d94e825e093a4e7c
Branch: androidx-master-dev
commit 366bb45ac5b9b06d1f6c9da0d94e825e093a4e7c
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Sep 16 13:29:48 2019
Add Fragment transition tests to androidx transitions
We should test fragment transitions for both androidx and support
transtions. This change copies over the transition tests from Fragments.
Test: this added tests
BUG: 140680619
Change-Id: I298535c1205686a75d205a65610af3fd43adeef8
M transition/transition/build.gradle
M transition/transition/src/androidTest/AndroidManifest.xml
A transition/transition/src/androidTest/java/androidx/transition/FragmentTestActivity.kt
A transition/transition/src/androidTest/java/androidx/transition/FragmentTestUtil.kt
M transition/transition/src/androidTest/java/androidx/transition/FragmentTransitionSupportTest.java
A transition/transition/src/androidTest/java/androidx/transition/FragmentTransitionTest.kt
A transition/transition/src/androidTest/java/androidx/transition/TrackingTransition.kt
A transition/transition/src/androidTest/java/androidx/transition/TrackingVisibility.java
A transition/transition/src/androidTest/java/androidx/transition/TransitionFragment.kt
A transition/transition/src/androidTest/res/layout/activity_content.xml
A transition/transition/src/androidTest/res/layout/double_container.xml
A transition/transition/src/androidTest/res/layout/fragment_scene1.xml
A transition/transition/src/androidTest/res/layout/fragment_scene2.xml
A transition/transition/src/androidTest/res/layout/fragment_scene3.xml
A transition/transition/src/androidTest/res/layout/simple_container.xml
A transition/transition/src/androidTest/res/layout/strict_view_fragment.xml
jb...@google.com <jb...@google.com> #11
This has been fixed internally and will be in available in the Fragment 1.2.0-beta01 release.
vi...@gmail.com <vi...@gmail.com> #12
Hi. When will the release 1.2.0-beta01 be?
il...@google.com <il...@google.com> #13
Should be ~next week.
Description
Version used:2.2.0-alpha02
Devices/Android versions reproduced on: All
If this is a bug in the library, we would appreciate if you could attach:
- Sample project to trigger the issue.
2019-09-09 12:57:19.033 27253-27253/com.example.android.motion E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.motion, PID: 27253
java.lang.ClassCastException: androidx.transition.TransitionSet cannot be cast to android.transition.Transition
at androidx.fragment.app.FragmentTransition.setListenerForTransitionEnd(FragmentTransition.java:307)
at androidx.fragment.app.FragmentTransition.configureTransitionsReordered(FragmentTransition.java:258)
at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:136)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2385)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2333)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2230)
at androidx.fragment.app.FragmentManager$3.run(FragmentManager.java:414)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7037)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
Works fine with alpha01.
Have a nice day !