Status Update
Comments
il...@google.com <il...@google.com> #2
reemission of the same liveData is racy
sk...@gmail.com <sk...@gmail.com> #3
il...@google.com <il...@google.com> #4
sk...@gmail.com <sk...@gmail.com> #5
@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>
cl...@google.com <cl...@google.com> #6
ap...@google.com <ap...@google.com> #7
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} )
}
cl...@google.com <cl...@google.com> #8
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
jb...@google.com <jb...@google.com>
pr...@google.com <pr...@google.com> #9
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-common:2.8.0-beta03
ig...@forzafootball.com <ig...@forzafootball.com> #10
I believe the real issue has not been addressed.
The very idea of implementing type-safe navigation is to abstract details away (like dealing with uri creation and parsing), thus decreasing runtime issues by making developers work with types, which is great, BUT for some reason type abstraction still leaks with uri-based backend details, and still obligates devs to write boilerplate. For example there could be
enum class Category {
@SerialName("started") Started,
@SerialName("ended_unexpectedly") EndedUnexpectedly
}
which could be used as a primitive within app, come from network of whatever and one would expect to safely use it as a property in route data class bc there is first-party support for enum serialization.
Despite all this assumptions app would fail, when EndedUnexpectedly
is used, but won't fail if Started
is used bc of _
, which is quite weird and moreover crash won't tell anything related to this specifically, only generic "can't find destination".
Forcing developers taking care of this is clearly the same issue we had before type-safe nav and which it was supposed to fix.
Description
Component used: Navigation
Version used: 2.8.0-beta02
Devices/Android versions reproduced on: emulator API 34
Basically,
RouteBuilder.Filled<T>
does not do any URL escaping. This causes runtime crashes during navigation with a non-escaped value the navigation library cannot find a target destination (as there is no argument match).This is unexpected as I'm using the abstraction for objects, with no URLs involved.