Status Update
Comments
ba...@gmail.com <ba...@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
ni...@gmail.com <ni...@gmail.com> #3
yea i'll take it.
ba...@gmail.com <ba...@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.
ni...@gmail.com <ni...@gmail.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()
}
}
lo...@gmail.com <lo...@gmail.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)
lo...@gmail.com <lo...@gmail.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} )
}
Description
Hi, I have been struggling with this for some time and finally decided to post there to make sure it is not me doing something wrong.
Please see attached POC, screen recording and sample crash log in the attached file. Project is created with Android Studio Koala Feature Drop | 2024.1.2 Canary 5
Issue:
Attached project demonstrates crash with a Room database but I use custom
PagingSource
because I also use Paging 3 with content providers such as call log and contacts.Due to my my project's needs, I need to invalidate
PagingSource
from outside every now and then. One of the reasons for that is inserting adverts to certain locations.I created
Invalidator
interface whichInvalidatingPagingSource
that extendsPagingSource
uses.InvalidatingPagingSource
in return extended by my custom paging source andViewModel
is provided with an instance ofInvalidator
so it can callInvalidator.invalidateNow()
when it needs to invalidate the paging source.This setup works fine when data is on screen and no scrolling is being done. However, if invalidation happens while user is scrolling app crashes with
I am not sure if I am being thick but, when I check the source of tryGetViewHolderForPositionByDeadline I see that it does these checks:
According to log however,
position 115(offset:115)
falls in tostate:207
so crash should not happen. What am I missing?Notes: