Fixed
Status Update
Comments
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
ga...@gmail.com <ga...@gmail.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.
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: snap-temp-L34200000699848945
commit 0849c43e4adbea7f96104d328f69a7c504b15ea1
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
https://android-review.googlesource.com/1436871
Branch: snap-temp-L34200000699848945
commit 0849c43e4adbea7f96104d328f69a7c504b15ea1
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
ap...@google.com <ap...@google.com> #10
Project: platform/frameworks/support
Branch: snap-temp-L04700000699849955
commit 2a048de5fbc9f21dfb785a8d015eec9c10930874
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
https://android-review.googlesource.com/1436748
Branch: snap-temp-L04700000699849955
commit 2a048de5fbc9f21dfb785a8d015eec9c10930874
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
ap...@google.com <ap...@google.com> #11
Project: platform/frameworks/support
Branch: snap-temp-L69500000699869549
commit f5f97b37c2bf85e50d6e819a0e2529f733e5c5c2
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
https://android-review.googlesource.com/1436413
Branch: snap-temp-L69500000699869549
commit f5f97b37c2bf85e50d6e819a0e2529f733e5c5c2
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
ap...@google.com <ap...@google.com> #12
Project: platform/frameworks/support
Branch: snap-temp-L31300000699869852
commit ebb79ab4f29f90cc26deb78c2ec9a7c06fd5240e
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
https://android-review.googlesource.com/1436915
Branch: snap-temp-L31300000699869852
commit ebb79ab4f29f90cc26deb78c2ec9a7c06fd5240e
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
ap...@google.com <ap...@google.com> #13
Project: platform/frameworks/support
Branch: snap-temp-L53700000699921463
commit a3d1426113e183c5c294e4c124f61b28ff8fa91d
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
https://android-review.googlesource.com/1436394
Branch: snap-temp-L53700000699921463
commit a3d1426113e183c5c294e4c124f61b28ff8fa91d
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
ap...@google.com <ap...@google.com> #14
Project: platform/frameworks/support
Branch: snap-temp-L25200000699921867
commit b7b6a6655ccad65b509d1b1e2b6e7c4d69a8f852
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
https://android-review.googlesource.com/1436922
Branch: snap-temp-L25200000699921867
commit b7b6a6655ccad65b509d1b1e2b6e7c4d69a8f852
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
ap...@google.com <ap...@google.com> #15
Project: platform/frameworks/support
Branch: snap-temp-L07700000699933785
commit 6e637298fa0127e409ab105309e19cb1869e2c76
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
https://android-review.googlesource.com/1436927
Branch: snap-temp-L07700000699933785
commit 6e637298fa0127e409ab105309e19cb1869e2c76
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jul 30 18:45:38 2020
override equals and hashCode for NavOptions
Lets implement these methods to simplify comparing NavOptions.
Equals method generated using studio.
Test: ./gradlew bOS
Bug: 161586466
Change-Id: I1beb8d06aa72ed6ad7bfe77d1f134a9793bc7e38
(cherry picked from commit 26288a9e8c3cb7ef4888ed252e2765bda7ab7d54)
M navigation/navigation-common/src/main/java/androidx/navigation/NavOptions.java
Description
Component used: Navigation Version used: 2.3.0
In some of our jvm tests we want to check that the right navigation is triggered. Since we are not on an actual device we are checking if the correct
NavDirections
object andNavOptions
object are passed to the navigator. HoweverNavOptions
currently does not overrideequals
andhashCode
which makes this more complicated than needed. Since allNavOptions
fields are eitherint
orboolean
this should be straightforward to do.