https://kotlinlang.org logo
Title
s

Shakil Karim

03/31/2023, 10:48 AM
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 ``````
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

Zach Klippenstein (he/him) [MOD]

04/04/2023, 6:21 PM
Please file a bug. Cc @Chuck Jazdzewski [G]
c

Chuck Jazdzewski [G]

04/05/2023, 8:41 PM
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

Shakil Karim

04/06/2023, 6:56 AM
i have this stack related to Thread 23
"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

Chuck Jazdzewski [G]

04/06/2023, 9:43 PM
aosp/2528169 should address this. I will requiest this being cherry-picked into 1.4 after it lands in android-main.