I'm updating a SnapshotStateList from a CoroutineS...
# compose
s
I'm updating a SnapshotStateList from a CoroutineScope and also reading same list from Composable
val list = SnapshotStateList<VoiceItem>()
appScope.launch {
voicesList.add(VoiceItem(id))
}
But i'm getting a lot of ANR in production app like this ``````
Copy code
at androidx.compose.runtime.snapshots.SnapshotStateList$StateListStateRecord.assign (SnapshotStateList.kt:458)
The main thread is blocked here. It is waiting, trying to acquire lock 0x0de00d89 (java.lang.Object), held by thread 23
  at androidx.compose.runtime.snapshots.SnapshotKt.overwriteUnusedRecordsLocked (Snapshot.kt:1941)
  at androidx.compose.runtime.snapshots.SnapshotKt.advanceGlobalSnapshot (Snapshot.kt:1773)
  at androidx.compose.runtime.snapshots.SnapshotKt.advanceGlobalSnapshot (Snapshot.kt)
  at androidx.compose.runtime.snapshots.SnapshotKt.access$advanceGlobalSnapshot (Snapshot.kt)
  at androidx.compose.runtime.snapshots.Snapshot$Companion.sendApplyNotifications (Snapshot.kt:568)
  at androidx.compose.ui.platform.GlobalSnapshotManager$ensureStarted$1.invokeSuspend (GlobalSnapshotManager.android.kt:46)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:106)
  at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch (AndroidUiDispatcher.android.kt:81)
  at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch (AndroidUiDispatcher.android.kt:41)
  at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run (AndroidUiDispatcher.android.kt:57)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:268)
  at android.app.ActivityThread.main (ActivityThread.java:8017)
  at java.lang.reflect.Method.invoke (Native method)
z
Please file a bug. Cc @Chuck Jazdzewski [G]
c
Can you include the thread 23 stack as well (if you have it).
Inspecting the code it looks likely that the threads will deadlock in
conditionalUpdate
in the
synchronized
call on around line 204. Is what you are seeing then I believe the code can be fixed by moving the
synchronized
call inside the
writable
call both in
conditionalUpdate
and
mutate
(which would have a a similar issue).
Never mind about the thread 23 request above, I see you included the equivalent in 269402895
s
i have this stack related to Thread 23
Copy code
"Timer-0" tid=23 Waiting
  at java.lang.Object.wait (Native method)
  at java.lang.Object.wait (Object.java:442)
  at java.lang.Object.wait (Object.java:568)
  at java.util.TimerThread.mainLoop (Timer.java:533)
  at java.util.TimerThread.run (Timer.java:512)
c
aosp/2528169 should address this. I will requiest this being cherry-picked into 1.4 after it lands in android-main.
691 Views