Fixed
Status Update
Comments
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
ap...@google.com <ap...@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.
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-main
commit f83ce34e8fddb3eb499f98c1262c346d11ee0205
Author: Sanura N'Jaka <sanura@google.com>
Date: Thu Aug 18 17:28:49 2022
Add project dependency constraint between lifecycle-livedata and lifecycle-livedata-core
Added bi-directional project version constraint between
lifecycle-lifedata and lifecycle-livedata-core. If both
artifacts are in the dependency tree, their versions
should match. This will now be enforced by gradle
automatically bumping up either version to meet constraint.
Test: N/A
Bug: 242871265
Change-Id: I3e67cbe8fa8bbc3999f0f463f22b484ea66ba988
M lifecycle/lifecycle-livedata-core/build.gradle
M lifecycle/lifecycle-livedata/build.gradle
https://android-review.googlesource.com/2189937
Branch: androidx-main
commit f83ce34e8fddb3eb499f98c1262c346d11ee0205
Author: Sanura N'Jaka <sanura@google.com>
Date: Thu Aug 18 17:28:49 2022
Add project dependency constraint between lifecycle-livedata and lifecycle-livedata-core
Added bi-directional project version constraint between
lifecycle-lifedata and lifecycle-livedata-core. If both
artifacts are in the dependency tree, their versions
should match. This will now be enforced by gradle
automatically bumping up either version to meet constraint.
Test: N/A
Bug: 242871265
Change-Id: I3e67cbe8fa8bbc3999f0f463f22b484ea66ba988
M lifecycle/lifecycle-livedata-core/build.gradle
M lifecycle/lifecycle-livedata/build.gradle
ap...@google.com <ap...@google.com> #10
Project: platform/frameworks/support
Branch: androidx-main
commit fe17ed80e60d5ec3bb42fe0552415424b7b3dde5
Author: Sanura N'Jaka <sanura@google.com>
Date: Thu Aug 18 17:36:11 2022
Add project dependency constraint between lifecycle-livedata and lifecycle-livedata-ktx
Added bi-directional project version constraint between
lifecycle-lifedata and lifecycle-livedata-ktx. If both
artifacts are in the dependency tree, their versions
should match. This will now be enforced by gradle
automatically bumping up either version to meet constraint.
Test: N/A
Bug: 242871265
Change-Id: Iba6d1ffb952fd20be91b813dcac193ecc1776173
M lifecycle/lifecycle-livedata-ktx/build.gradle
M lifecycle/lifecycle-livedata/build.gradle
https://android-review.googlesource.com/2189940
Branch: androidx-main
commit fe17ed80e60d5ec3bb42fe0552415424b7b3dde5
Author: Sanura N'Jaka <sanura@google.com>
Date: Thu Aug 18 17:36:11 2022
Add project dependency constraint between lifecycle-livedata and lifecycle-livedata-ktx
Added bi-directional project version constraint between
lifecycle-lifedata and lifecycle-livedata-ktx. If both
artifacts are in the dependency tree, their versions
should match. This will now be enforced by gradle
automatically bumping up either version to meet constraint.
Test: N/A
Bug: 242871265
Change-Id: Iba6d1ffb952fd20be91b813dcac193ecc1776173
M lifecycle/lifecycle-livedata-ktx/build.gradle
M lifecycle/lifecycle-livedata/build.gradle
ap...@google.com <ap...@google.com> #11
Project: platform/frameworks/support
Branch: androidx-main
commit 1e948aed8d0c01823ae60258ade0694da728b36d
Author: Sanura N'Jaka <sanura@google.com>
Date: Thu Aug 18 17:40:29 2022
Add project dependency constraint between lifecycle-livedata-core and lifecycle-livedata-core-ktx
Added bi-directional project version constraint between
lifecycle-lifedata-core and lifecycle-livedata-core-ktx.
If both artifacts are in the dependency tree, their
versions should match. This will now be enforced by gradle
automatically bumping up either version to meet constraint.
Test: N/A
Bug: 242871265
Change-Id: I6c6dd9de2e252217095c60de8ef577be6d940f1a
M lifecycle/lifecycle-livedata-core/build.gradle
M lifecycle/lifecycle-livedata-core-ktx/build.gradle
https://android-review.googlesource.com/2189941
Branch: androidx-main
commit 1e948aed8d0c01823ae60258ade0694da728b36d
Author: Sanura N'Jaka <sanura@google.com>
Date: Thu Aug 18 17:40:29 2022
Add project dependency constraint between lifecycle-livedata-core and lifecycle-livedata-core-ktx
Added bi-directional project version constraint between
lifecycle-lifedata-core and lifecycle-livedata-core-ktx.
If both artifacts are in the dependency tree, their
versions should match. This will now be enforced by gradle
automatically bumping up either version to meet constraint.
Test: N/A
Bug: 242871265
Change-Id: I6c6dd9de2e252217095c60de8ef577be6d940f1a
M lifecycle/lifecycle-livedata-core/build.gradle
M lifecycle/lifecycle-livedata-core-ktx/build.gradle
ap...@google.com <ap...@google.com> #12
Project: platform/frameworks/support
Branch: androidx-main
commit 325aa99d830327ccf016231f9836cf04db65c3ff
Author: Sanura N'Jaka <sanura@google.com>
Date: Mon Aug 22 22:23:18 2022
Add project dependency constraint between lifecycle-common and lifecycle-livedata-core
Added bi-directional project version constraint between
lifecycle-common and lifecycle-livedata-core. If both
artifacts are in the dependency tree, their versions
should match. This will now be enforced by gradle
automatically bumping up either version to meet constraint.
Test: N/A
Bug: 242871265
Change-Id: I22e0fda00e22bc4fc56ac1bf5b7dcd2369ad533e
M lifecycle/lifecycle-livedata-core/build.gradle
M lifecycle/lifecycle-common/build.gradle
https://android-review.googlesource.com/2192537
Branch: androidx-main
commit 325aa99d830327ccf016231f9836cf04db65c3ff
Author: Sanura N'Jaka <sanura@google.com>
Date: Mon Aug 22 22:23:18 2022
Add project dependency constraint between lifecycle-common and lifecycle-livedata-core
Added bi-directional project version constraint between
lifecycle-common and lifecycle-livedata-core. If both
artifacts are in the dependency tree, their versions
should match. This will now be enforced by gradle
automatically bumping up either version to meet constraint.
Test: N/A
Bug: 242871265
Change-Id: I22e0fda00e22bc4fc56ac1bf5b7dcd2369ad533e
M lifecycle/lifecycle-livedata-core/build.gradle
M lifecycle/lifecycle-common/build.gradle
ap...@google.com <ap...@google.com> #13
Project: platform/frameworks/support
Branch: androidx-main
commit 27355f7c30e816f6636928caeef29d473b896e28
Author: Sanura N'Jaka <sanura@google.com>
Date: Wed Aug 24 22:41:48 2022
Add project dependency constraint between lifecycle-viewmodel-savedstate and lifecycle-livedata-core
Added bi-directional project version constraint between
lifecycle-viewmodel-savedstate and lifecycle-livedata-core.
If both artifacts are in the dependency tree, their versions
should match. This will now be enforced by gradle automatically
bumping up either version to meet constraint.
Test: N/A
Fixes: 242871265
Change-Id: I94cc3ddd0f86033653c1477cf3f8ad8a1d93adae
M lifecycle/lifecycle-livedata-core/build.gradle
M lifecycle/lifecycle-viewmodel-savedstate/build.gradle
https://android-review.googlesource.com/2193733
Branch: androidx-main
commit 27355f7c30e816f6636928caeef29d473b896e28
Author: Sanura N'Jaka <sanura@google.com>
Date: Wed Aug 24 22:41:48 2022
Add project dependency constraint between lifecycle-viewmodel-savedstate and lifecycle-livedata-core
Added bi-directional project version constraint between
lifecycle-viewmodel-savedstate and lifecycle-livedata-core.
If both artifacts are in the dependency tree, their versions
should match. This will now be enforced by gradle automatically
bumping up either version to meet constraint.
Test: N/A
Fixes: 242871265
Change-Id: I94cc3ddd0f86033653c1477cf3f8ad8a1d93adae
M lifecycle/lifecycle-livedata-core/build.gradle
M lifecycle/lifecycle-viewmodel-savedstate/build.gradle
ap...@google.com <ap...@google.com> #14
Project: platform/frameworks/support
Branch: androidx-main
commit 0598f5400a797fc9e31858e0d8a1b575ad7158a7
Author: Sanura N'Jaka <sanura@google.com>
Date: Thu Aug 18 18:28:20 2022
Add project dependency constraint between lifecycle-viewmodel-savedstate and lifecycle-viewmodel-compose
Added bi-directional project version constraint between
lifecycle-viewmodel-savedstate and lifecycle-viewmodel-compose.
If both artifacts are in the dependency tree, their versions
should match. This will now be enforced by gradle automatically
bumping up either version to meet constraint.
Test: N/A
Bug: 242871265
Change-Id: I2810d3afbe0cb8e8e387d1bc64eb3c698285d471
M lifecycle/lifecycle-viewmodel-savedstate/build.gradle
M lifecycle/lifecycle-viewmodel-compose/build.gradle
https://android-review.googlesource.com/2190016
Branch: androidx-main
commit 0598f5400a797fc9e31858e0d8a1b575ad7158a7
Author: Sanura N'Jaka <sanura@google.com>
Date: Thu Aug 18 18:28:20 2022
Add project dependency constraint between lifecycle-viewmodel-savedstate and lifecycle-viewmodel-compose
Added bi-directional project version constraint between
lifecycle-viewmodel-savedstate and lifecycle-viewmodel-compose.
If both artifacts are in the dependency tree, their versions
should match. This will now be enforced by gradle automatically
bumping up either version to meet constraint.
Test: N/A
Bug: 242871265
Change-Id: I2810d3afbe0cb8e8e387d1bc64eb3c698285d471
M lifecycle/lifecycle-viewmodel-savedstate/build.gradle
M lifecycle/lifecycle-viewmodel-compose/build.gradle
na...@google.com <na...@google.com> #15
This bug was linked in a change in the following release(s):
androidx.lifecycle:lifecycle-common:2.6.0-alpha02
androidx.lifecycle:lifecycle-livedata:2.6.0-alpha02
androidx.lifecycle:lifecycle-livedata-core:2.6.0-alpha02
androidx.lifecycle:lifecycle-livedata-core-ktx:2.6.0-alpha02
androidx.lifecycle:lifecycle-livedata-ktx:2.6.0-alpha02
androidx.lifecycle:lifecycle-reactivestreams:2.6.0-alpha02
androidx.lifecycle:lifecycle-reactivestreams-ktx:2.6.0-alpha02
androidx.lifecycle:lifecycle-runtime:2.6.0-alpha02
androidx.lifecycle:lifecycle-runtime-compose:2.6.0-alpha02
androidx.lifecycle:lifecycle-runtime-ktx:2.6.0-alpha02
androidx.lifecycle:lifecycle-runtime-testing:2.6.0-alpha02
androidx.lifecycle:lifecycle-viewmodel:2.6.0-alpha02
androidx.lifecycle:lifecycle-viewmodel-compose:2.6.0-alpha02
androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.0-alpha02
androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.0-alpha02
da...@google.com <da...@google.com> #16
This release seems to have conflicting artifacts in the classpath. When both:
androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.0-alpha02
androidx-lifecycle:lifecycle-livedata-ktx:2.6.0-alpha02
are added as dependencies, the following error pops up:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':sync:sync-test:checkProdDebugAndroidTestDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
> Duplicate class androidx.lifecycle.ViewModelLazy found in modules lifecycle-viewmodel-2.6.0-alpha02-runtime (androidx.lifecycle:lifecycle-viewmodel:2.6.0-alpha02) and lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1)
Duplicate class androidx.lifecycle.ViewTreeViewModelKt found in modules lifecycle-viewmodel-2.6.0-alpha02-runtime (androidx.lifecycle:lifecycle-viewmodel:2.6.0-alpha02) and lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1)
Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
Downgrading to 2.6.0-alpha01
fixes this.
sa...@google.com <sa...@google.com> #17
As an update to the above comment from TJ, this issue has been fixed and will be available in Lifecycle 2.6.0-alpha03.
na...@google.com <na...@google.com> #18
The following release(s) address this bug:
androidx.lifecycle:lifecycle-runtime:2.6.0-alpha03
androidx.lifecycle:lifecycle-runtime-compose:2.6.0-alpha03
androidx.lifecycle:lifecycle-viewmodel-compose:2.6.0-alpha03
androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.0-alpha03
Description
Component used: Lifecycle
Version used: 2.6.0-alpha01
Until feature requests such as b/146802533 are released, Gradle does not do any enforcement that Lifecycle artifacts are of the same version (i.e., you could mix and match
lifecycle-common:2.6.0-alpha01
withlifecycle-runtime:2.5.1
).Gradle supports constraints , which ensure that upgrading a transitive dependency will also upgrade other dependencies.
We should manually add two way constraints, similarly to what was done for Paging in b/235256201 , to the various lifecycle artifacts, which will help Gradle enforce the same version policy we intend.
The pairs of artifacts we should add constraints to should match the dependencies we have right now, which should mean the list looks something like: