Fixed
Status Update
Comments
lo...@gmail.com <lo...@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
ag...@gmail.com <ag...@gmail.com> #3
yea i'll take it.
be...@google.com <be...@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()
}
}
il...@google.com <il...@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 3c0404251aeb98801b422072f86127739fa59f60
Author: Ben Weiss <benweiss@google.com>
Date: Wed Apr 22 21:54:02 2020
Add reified fragment for dynamic fragments
Bug: 148969800
Test: gw cAT
Change-Id: Ie03d9ed0b21b854d6595c0208ce23a4c13294273
M navigation/navigation-dynamic-features-fragment/api/2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-fragment/api/current.txt
M navigation/navigation-dynamic-features-fragment/api/public_plus_experimental_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-fragment/api/public_plus_experimental_current.txt
M navigation/navigation-dynamic-features-fragment/api/restricted_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-fragment/api/restricted_current.txt
M navigation/navigation-dynamic-features-fragment/src/androidTest/java/androidx/navigation/dynamicfeatures/fragment/DynamicFragmentNavigatorDestinationBuilderTest.kt
M navigation/navigation-dynamic-features-fragment/src/main/java/androidx/navigation/dynamicfeatures/fragment/DynamicFragmentNavigatorDestinationBuilder.kt
https://android-review.googlesource.com/1293554
Branch: androidx-master-dev
commit 3c0404251aeb98801b422072f86127739fa59f60
Author: Ben Weiss <benweiss@google.com>
Date: Wed Apr 22 21:54:02 2020
Add reified fragment for dynamic fragments
Bug: 148969800
Test: gw cAT
Change-Id: Ie03d9ed0b21b854d6595c0208ce23a4c13294273
M navigation/navigation-dynamic-features-fragment/api/2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-fragment/api/current.txt
M navigation/navigation-dynamic-features-fragment/api/public_plus_experimental_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-fragment/api/public_plus_experimental_current.txt
M navigation/navigation-dynamic-features-fragment/api/restricted_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-fragment/api/restricted_current.txt
M navigation/navigation-dynamic-features-fragment/src/androidTest/java/androidx/navigation/dynamicfeatures/fragment/DynamicFragmentNavigatorDestinationBuilderTest.kt
M navigation/navigation-dynamic-features-fragment/src/main/java/androidx/navigation/dynamicfeatures/fragment/DynamicFragmentNavigatorDestinationBuilder.kt
ap...@google.com <ap...@google.com> #10
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 5aa702c7dc0b2888fcc051f6777e56c3d2397e5c
Author: Ian Lake <ilake@google.com>
Date: Wed Apr 22 14:54:47 2020
Add includeDynamic Builder
Allow developers to add include-dynamic destinations
via the Kotlin DSL.
Bug: 148969800
Test: cAT
Change-Id: Ic92a2201cc44526174b65ca433433d1dc169543f
M navigation/navigation-dynamic-features-runtime/api/2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/current.txt
M navigation/navigation-dynamic-features-runtime/api/public_plus_experimental_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/public_plus_experimental_current.txt
M navigation/navigation-dynamic-features-runtime/api/restricted_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/restricted_current.txt
A navigation/navigation-dynamic-features-runtime/src/androidTest/java/androidx/navigation/dynamicfeatures/DynamicIncludeNavGraphBuilderTest.kt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/DynamicIncludeGraphNavigator.kt
A navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/DynamicIncludeNavGraphBuilder.kt
https://android-review.googlesource.com/1287600
Branch: androidx-master-dev
commit 5aa702c7dc0b2888fcc051f6777e56c3d2397e5c
Author: Ian Lake <ilake@google.com>
Date: Wed Apr 22 14:54:47 2020
Add includeDynamic Builder
Allow developers to add include-dynamic destinations
via the Kotlin DSL.
Bug: 148969800
Test: cAT
Change-Id: Ic92a2201cc44526174b65ca433433d1dc169543f
M navigation/navigation-dynamic-features-runtime/api/2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/current.txt
M navigation/navigation-dynamic-features-runtime/api/public_plus_experimental_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/public_plus_experimental_current.txt
M navigation/navigation-dynamic-features-runtime/api/restricted_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/restricted_current.txt
A navigation/navigation-dynamic-features-runtime/src/androidTest/java/androidx/navigation/dynamicfeatures/DynamicIncludeNavGraphBuilderTest.kt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/DynamicIncludeGraphNavigator.kt
A navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/DynamicIncludeNavGraphBuilder.kt
ap...@google.com <ap...@google.com> #11
Project: platform/frameworks/support
Branch: androidx-master-dev
commit a386c72b7b40597559c8eecb3907ec6a1dedf3b0
Author: Ian Lake <ilake@google.com>
Date: Wed Apr 22 16:31:37 2020
Limit Dynamic Kotlin DSL to DynamicNavGraphBuilder
Dynamic Destinations need to be placed inside
a DynamicNavGraph to function properly, so we
should limit the Dynamic Kotlin DSLs to only
apply to that DynamicNavGraphBuilder scope, rather
than to any Kotlin DSL.
Test: tests still pass
BUG: 148969800
Change-Id: Ia9b54f60f19dcadc617201e582abaca51c097e78
M navigation/navigation-dynamic-features-fragment/api/2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-fragment/api/current.txt
M navigation/navigation-dynamic-features-fragment/api/public_plus_experimental_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-fragment/api/public_plus_experimental_current.txt
M navigation/navigation-dynamic-features-fragment/api/restricted_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-fragment/api/restricted_current.txt
M navigation/navigation-dynamic-features-fragment/src/main/java/androidx/navigation/dynamicfeatures/fragment/DynamicFragmentNavigatorDestinationBuilder.kt
M navigation/navigation-dynamic-features-runtime/api/2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/current.txt
M navigation/navigation-dynamic-features-runtime/api/public_plus_experimental_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/public_plus_experimental_current.txt
M navigation/navigation-dynamic-features-runtime/api/restricted_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/restricted_current.txt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/DynamicActivityNavigatorDestinationBuilder.kt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/DynamicIncludeNavGraphBuilder.kt
https://android-review.googlesource.com/1293393
Branch: androidx-master-dev
commit a386c72b7b40597559c8eecb3907ec6a1dedf3b0
Author: Ian Lake <ilake@google.com>
Date: Wed Apr 22 16:31:37 2020
Limit Dynamic Kotlin DSL to DynamicNavGraphBuilder
Dynamic Destinations need to be placed inside
a DynamicNavGraph to function properly, so we
should limit the Dynamic Kotlin DSLs to only
apply to that DynamicNavGraphBuilder scope, rather
than to any Kotlin DSL.
Test: tests still pass
BUG: 148969800
Change-Id: Ia9b54f60f19dcadc617201e582abaca51c097e78
M navigation/navigation-dynamic-features-fragment/api/2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-fragment/api/current.txt
M navigation/navigation-dynamic-features-fragment/api/public_plus_experimental_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-fragment/api/public_plus_experimental_current.txt
M navigation/navigation-dynamic-features-fragment/api/restricted_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-fragment/api/restricted_current.txt
M navigation/navigation-dynamic-features-fragment/src/main/java/androidx/navigation/dynamicfeatures/fragment/DynamicFragmentNavigatorDestinationBuilder.kt
M navigation/navigation-dynamic-features-runtime/api/2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/current.txt
M navigation/navigation-dynamic-features-runtime/api/public_plus_experimental_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/public_plus_experimental_current.txt
M navigation/navigation-dynamic-features-runtime/api/restricted_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/restricted_current.txt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/DynamicActivityNavigatorDestinationBuilder.kt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/DynamicIncludeNavGraphBuilder.kt
ap...@google.com <ap...@google.com> #12
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 74f1b7591f549e471dd86e23c43a6f0a04d128d4
Author: Ian Lake <ilake@google.com>
Date: Wed Apr 22 17:01:14 2020
Move optional parameters to be DSL variables
Instead of requiring that you define optional
parameters when constructing the DynamicNavGraph,
make them part of the DSL to mirror what we do
for the other builders.
This also fixes an issue with the progress
destination of 0 on restore.
Test: updated tests pass
BUG: 148969800
Change-Id: I2e897711da375e11e14dab5acf9c5117b38b63f3
M navigation/navigation-dynamic-features-runtime/api/2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/current.txt
M navigation/navigation-dynamic-features-runtime/api/public_plus_experimental_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/public_plus_experimental_current.txt
M navigation/navigation-dynamic-features-runtime/api/restricted_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/restricted_current.txt
M navigation/navigation-dynamic-features-runtime/src/androidTest/java/androidx/navigation/dynamicfeatures/DynamicNavGraphBuilderTest.kt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/DynamicNavGraphBuilder.kt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/NavController.kt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/NavHost.kt
https://android-review.googlesource.com/1293694
Branch: androidx-master-dev
commit 74f1b7591f549e471dd86e23c43a6f0a04d128d4
Author: Ian Lake <ilake@google.com>
Date: Wed Apr 22 17:01:14 2020
Move optional parameters to be DSL variables
Instead of requiring that you define optional
parameters when constructing the DynamicNavGraph,
make them part of the DSL to mirror what we do
for the other builders.
This also fixes an issue with the progress
destination of 0 on restore.
Test: updated tests pass
BUG: 148969800
Change-Id: I2e897711da375e11e14dab5acf9c5117b38b63f3
M navigation/navigation-dynamic-features-runtime/api/2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/current.txt
M navigation/navigation-dynamic-features-runtime/api/public_plus_experimental_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/public_plus_experimental_current.txt
M navigation/navigation-dynamic-features-runtime/api/restricted_2.3.0-alpha06.txt
M navigation/navigation-dynamic-features-runtime/api/restricted_current.txt
M navigation/navigation-dynamic-features-runtime/src/androidTest/java/androidx/navigation/dynamicfeatures/DynamicNavGraphBuilderTest.kt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/DynamicNavGraphBuilder.kt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/NavController.kt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/NavHost.kt
il...@google.com <il...@google.com> #13
We've made significant improvements to the Kotlin DSL support for Dynamic Navigation and it'll be available in Navigation 2.3.0-alpha06.
lo...@gmail.com <lo...@gmail.com> #14
Is there any documentation to discover the changes?
Description
Component used: Navigation Version used: 2.3.0-alpha01
Currently, the Navigation Kotlin DSL only allows you to add NavGraph, FragmentNavigator.Destination, and other non-dynamic feature module aware destinations.
A parallel set of DSL extensions should be built to allow dynamic feature module destinations to easily be added to the Kotlin DSL. These would be distinguished from the others by the package name of the import.