Anamorphosee / stacktrace-decoroutinator

Small lib for recovering stack trace in exceptions thrown in Kotlin coroutines
Apache License 2.0
205 stars 5 forks source link

Android: Fatal exception in coroutines machinery for CancellableContinuation #39

Closed nordfalk closed 1 week ago

nordfalk commented 1 month ago

This exception has happened twice on a user's phone. No one else has seen it (its running on 100 phones), and before and after it worked fine on this users phone.

kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[Dispatchers.IO, Continuation at kotlinx.coroutines.channels.ProduceKt.awaitClose(Produce.kt:153)@44e6220]){Cancelled}@b4f536b. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
at kotlinx.coroutines.DebugStringsKt.e(DispatchedTask.kt:43)
at kotlinx.coroutines.DebugStringsKt.run(DispatchedTask.kt:213)
at kotlinx.coroutines.internal.LimitedDispatcher$a.run(LimitedDispatcher.kt:4)
at K5.i.run(Tasks.kt:3)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [g{Cancelling}@f8dbb47, Dispatchers.IO]
Caused by: java.lang.NullPointerException
at dev.reformator.stacktracedecoroutinator.common.internal.BaseSpecMethodsRegistry.getSpecMethodFactoriesByStacktraceElement(specMethodsRegistry-common.kt:87)
at dev.reformator.stacktracedecoroutinator.common.internal.AwakenerKt.callSpecMethods(awakener.kt:9)
at dev.reformator.stacktracedecoroutinator.common.internal.AwakenerKt.awake(awakener.kt:80)
at dev.reformator.stacktracedecoroutinator.common.internal.Provider.awakeBaseContinuation(provider-impl.kt:15)
at dev.reformator.stacktracedecoroutinator.provider.DecoroutinatorProviderApiKt.awakeBaseContinuation(provider-api.kt:15)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
at kotlinx.coroutines.DebugStringsKt.run(DispatchedTask.kt:115)
    ... 6 more

This is a release build with

plugins {
    id("dev.reformator.stacktracedecoroutinator") version "2.4.5"
    id("com.android.application")
    id("com.google.gms.google-services")
    id("com.datadoghq.dd-sdk-android-gradle-plugin")
    id("kotlin-android")
}
Anamorphosee commented 1 month ago

Thank you for the issue. I’ll be able to check it on the next week

nordfalk commented 1 month ago

Sure! Some more info:

The 2 crashes happened within 15 seconds of time. The users had used the app a long time before they happened Startup image

SD reports no problems at every invocation: image

(numerouse use of coroutines)

Crash 1+2: image

After the crashes the user was using the app for a long time, with no problems: image

nordfalk commented 1 month ago

It was in Android 14: image

I'll get back with more crash reports next week if it happens again

nordfalk commented 1 month ago

200 users have used it by now. No other crashes has occurred. I'll get back to you by Friday or if another crash has occured.

nordfalk commented 1 month ago

No crashes since that first one :partying_face: Next week I'll try with 1000 users and see how it goes, but it seems this was a one-time-issue.

nordfalk commented 2 weeks ago

Hi there, Unfortunately the crash still sometimes appear: image

The build with SD is currently running on 20% of our users.... so you can see that SD crashes would be completely dominant if I'd do a 100% rollout to all users.

Here are some stack traces from Google Play:

Redmi aether (Redmi 12C) Android 14 (SDK 34):

Exception kotlinx.coroutines.CoroutinesInternalError:
  at kotlinx.coroutines.DispatchedTask.handleFatalException (DispatchedTask.kt:144)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:115)
  at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run (LimitedDispatcher.kt:115)
  at kotlinx.coroutines.scheduling.TaskImpl.run (Tasks.kt:100)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.kt:584)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.kt:793)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.kt:697)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.kt:684)
Caused by java.lang.ArrayIndexOutOfBoundsException: length=68; index=68
  at dev.reformator.stacktracedecoroutinator.common.internal.AwakenerKt.recoveryExplicitStacktrace (awakener.kt:103)
  at dev.reformator.stacktracedecoroutinator.common.internal.AwakenerKt.awake (awakener.kt:28)
  at dev.reformator.stacktracedecoroutinator.common.internal.Provider.awakeBaseContinuation (provider-impl.kt:43)
  at dev.reformator.stacktracedecoroutinator.provider.DecoroutinatorProviderApiKt.awakeBaseContinuation (provider-api.kt:47)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:21)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:104)

samsung a50 (Galaxy A50) Android 11 (SDK 30):

Exception kotlinx.coroutines.CoroutinesInternalError:
  at kotlinx.coroutines.DispatchedTask.handleFatalException (DispatchedTask.kt:144)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:115)
  at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run (LimitedDispatcher.kt:115)
  at kotlinx.coroutines.scheduling.TaskImpl.run (Tasks.kt:100)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.kt:584)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.kt:793)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.kt:697)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.kt:684)
Caused by java.lang.ArrayIndexOutOfBoundsException: length=69; index=69
  at dev.reformator.stacktracedecoroutinator.common.internal.AwakenerKt.recoveryExplicitStacktrace (awakener.kt:103)
  at dev.reformator.stacktracedecoroutinator.common.internal.AwakenerKt.awake (awakener.kt:28)
  at dev.reformator.stacktracedecoroutinator.common.internal.Provider.awakeBaseContinuation (provider-impl.kt:43)
  at dev.reformator.stacktracedecoroutinator.provider.DecoroutinatorProviderApiKt.awakeBaseContinuation (provider-api.kt:47)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:21)
  at kotlinx.coroutines.internal.ScopeCoroutine.afterResume (Scopes.kt:32)
  at kotlinx.coroutines.AbstractCoroutine.resumeWith (AbstractCoroutine.kt:102)
  at dev.reformator.stacktracedecoroutinator.common.internal.AwakenerKt.awake (awakener.kt:47)
  at dev.reformator.stacktracedecoroutinator.common.internal.Provider.awakeBaseContinuation (provider-impl.kt:43)
  at dev.reformator.stacktracedecoroutinator.provider.DecoroutinatorProviderApiKt.awakeBaseContinuation (provider-api.kt:47)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:21)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:104)

samsung e3q (Galaxy S24 Ultra) - Android 14 (SDK 34)

Exception kotlinx.coroutines.CoroutinesInternalError:
  at kotlinx.coroutines.DispatchedTask.handleFatalException (DispatchedTask.kt:144)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:115)
  at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch (AndroidUiDispatcher.android.kt:81)
  at androidx.compose.ui.platform.AndroidUiDispatcher.access$setScheduledFrameDispatch$p (AndroidUiDispatcher.android.kt:41)
  at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch (AndroidUiDispatcher.android.kt:41)
  at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame (AndroidUiDispatcher.android.kt:68)
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1687)
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1698)
  at android.view.Choreographer.doCallbacks (Choreographer.java:1153)
  at android.view.Choreographer.doFrame (Choreographer.java:1069)
  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1646)
  at android.os.Handler.handleCallback (Handler.java:958)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:230)
  at android.os.Looper.loop (Looper.java:319)
  at android.app.ActivityThread.main (ActivityThread.java:8918)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:608)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1103)
Caused by java.lang.IllegalAccessException:
  at java.lang.invoke.MethodHandles$Lookup.throwMakeAccessException (MethodHandles.java:2181)
  at java.lang.invoke.MethodHandles$Lookup.checkAccess (MethodHandles.java:2130)
  at java.lang.invoke.MethodHandles$Lookup.findStatic (MethodHandles.java:848)
  at dev.reformator.stacktracedecoroutinator.generatorandroid.AndroidSpecMethodsRegistry.generateSpecMethodFactories (specMethodsRegistry-generator-android.kt:41)
  at dev.reformator.stacktracedecoroutinator.common.internal.BaseSpecMethodsRegistry.getSpecMethodFactoriesByStacktraceElement (specMethodsRegistry-common.kt:51)
  at dev.reformator.stacktracedecoroutinator.common.internal.AwakenerKt.callSpecMethods (awakener.kt:63)
  at dev.reformator.stacktracedecoroutinator.common.internal.AwakenerKt.awake (awakener.kt:32)
  at dev.reformator.stacktracedecoroutinator.common.internal.Provider.awakeBaseContinuation (provider-impl.kt:43)
  at dev.reformator.stacktracedecoroutinator.provider.DecoroutinatorProviderApiKt.awakeBaseContinuation (provider-api.kt:47)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:21)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:106)

samsung z3s (Galaxy S20 Ultra 5G) Android 13 (SDK 33)

Exception kotlinx.coroutines.CoroutinesInternalError:
  at kotlinx.coroutines.DispatchedTask.handleFatalException (DispatchedTask.kt:144)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:115)
  at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run (LimitedDispatcher.kt:115)
  at kotlinx.coroutines.scheduling.TaskImpl.run (Tasks.kt:100)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.kt:584)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.kt:793)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.kt:697)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.kt:684)
Caused by java.lang.NullPointerException:
  at dev.reformator.stacktracedecoroutinator.common.internal.BaseSpecMethodsRegistry.getSpecMethodFactoriesByStacktraceElement (specMethodsRegistry-common.kt:66)
  at dev.reformator.stacktracedecoroutinator.common.internal.AwakenerKt.callSpecMethods (awakener.kt:63)
  at dev.reformator.stacktracedecoroutinator.common.internal.AwakenerKt.awake (awakener.kt:32)
  at dev.reformator.stacktracedecoroutinator.common.internal.Provider.awakeBaseContinuation (provider-impl.kt:43)
  at dev.reformator.stacktracedecoroutinator.provider.DecoroutinatorProviderApiKt.awakeBaseContinuation (provider-api.kt:47)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:21)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:104)

Even though it cant be see on the above stacktraces I have a suspicion that the problem is more appearent when using Jetpack Compose background coroutine tasks, such as LaunchedEffect...

Anamorphosee commented 1 week ago

fixed at 2.4.6