question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StackOverflow in DispatchedContinuation

See original GitHub issue

We are having a a bug in a class used to instantiate heavy objects in background thread. Seems to happen since bumping coroutines to 1.4.0. Looks like something is cycling in an endless loop. A class:

class AsyncSingletonContainer<T>(scope: CoroutineScope, private val createObject: () -> T) {

    private val cachedSingletonObject = scope.async(Dispatchers.Default) { createObject() }

    suspend fun getInstance(): T = cachedSingletonObject.await()
}

Stack trace: Fatal Exception: r4.a.i0: Fatal exception in coroutines machinery for DispatchedContinuation[Dispatchers.Default, Continuation at **.AsyncSingletonContainer$cachedSingletonObject$1.invokeSuspend(AsyncSingletonContainer.kt)@f734c38]. Please read KDoc to ‘handleFatalException’ method and report this incident to maintainers at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.java:144) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:115) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:571) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:738) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:678) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:665)

Caused by java.lang.StackOverflowError: stack size 1037KB at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:452) at java.lang.StringBuilder.append(StringBuilder.java:137) at kotlinx.coroutines.CancellableContinuationImpl.toString(CancellableContinuationImpl.java:506) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.ResumeAwaitOnCompletion.toString(ResumeAwaitOnCompletion.java:1414) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.DisposeOnCancel.toString(DisposeOnCancel.java:385) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CompletedContinuation.toString(CompletedContinuation.java:18) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CancellableContinuationImpl.toString(CancellableContinuationImpl.java:506) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.ResumeAwaitOnCompletion.toString(ResumeAwaitOnCompletion.java:1414) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.DisposeOnCancel.toString(DisposeOnCancel.java:385) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CompletedContinuation.toString(CompletedContinuation.java:18) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CancellableContinuationImpl.toString(CancellableContinuationImpl.java:506) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.ResumeAwaitOnCompletion.toString(ResumeAwaitOnCompletion.java:1414) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.DisposeOnCancel.toString(DisposeOnCancel.java:385) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CompletedContinuation.toString(CompletedContinuation.java:18) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CancellableContinuationImpl.toString(CancellableContinuationImpl.java:506) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.ResumeAwaitOnCompletion.toString(ResumeAwaitOnCompletion.java:1414) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.DisposeOnCancel.toString(DisposeOnCancel.java:385) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CompletedContinuation.toString(CompletedContinuation.java:18) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CancellableContinuationImpl.toString(CancellableContinuationImpl.java:506) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.ResumeAwaitOnCompletion.toString(ResumeAwaitOnCompletion.java:1414) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.DisposeOnCancel.toString(DisposeOnCancel.java:385) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CompletedContinuation.toString(CompletedContinuation.java:18) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CancellableContinuationImpl.toString(CancellableContinuationImpl.java:506) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.ResumeAwaitOnCompletion.toString(ResumeAwaitOnCompletion.java:1414) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.DisposeOnCancel.toString(DisposeOnCancel.java:385) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CompletedContinuation.toString(CompletedContinuation.java:18) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CancellableContinuationImpl.toString(CancellableContinuationImpl.java:506) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.ResumeAwaitOnCompletion.toString(ResumeAwaitOnCompletion.java:1414) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.DisposeOnCancel.toString(DisposeOnCancel.java:385) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CompletedContinuation.toString(CompletedContinuation.java:18) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CancellableContinuationImpl.toString(CancellableContinuationImpl.java:506) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.ResumeAwaitOnCompletion.toString(ResumeAwaitOnCompletion.java:1414) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.DisposeOnCancel.toString(DisposeOnCancel.java:385) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CompletedContinuation.toString(CompletedContinuation.java:18) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CancellableContinuationImpl.toString(CancellableContinuationImpl.java:506) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.ResumeAwaitOnCompletion.toString(ResumeAwaitOnCompletion.java:1414) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.DisposeOnCancel.toString(DisposeOnCancel.java:385) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CompletedContinuation.toString(CompletedContinuation.java:18) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CancellableContinuationImpl.toString(CancellableContinuationImpl.java:506) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.ResumeAwaitOnCompletion.toString(ResumeAwaitOnCompletion.java:1414) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.DisposeOnCancel.toString(DisposeOnCancel.java:385) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CompletedContinuation.toString(CompletedContinuation.java:18) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.CancellableContinuationImpl.toString(CancellableContinuationImpl.java:506) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.ResumeAwaitOnCompletion.toString(ResumeAwaitOnCompletion.java:1414) at java.lang.String.valueOf(String.java:2827) at java.lang.StringBuilder.append(StringBuilder.java:132) at kotlinx.coroutines.JobSupport.completeStateFinalization(JobSupport.java:320) at kotlinx.coroutines.JobSupport.tryFinalizeSimpleState(JobSupport.java:295) at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.java:853) at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.java:825) at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.java:111) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:46) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:106) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:571) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:738) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:678) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:665)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:25
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

17reactions
elizarovcommented, Nov 19, 2020

Yes. It will a part of 1.4.2

8reactions
PhBogdanovcommented, Nov 19, 2020

Yes. It will a part of 1.4.2

Is there any information when the release comes?

Read more comments on GitHub >

github_iconTop Results From Across the Web

kotlinx.coroutines.CompletableDeferredImpl cannot be cast to ...
Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?
Read more >
JVM / IR: ClassCastException caused by runBlocking awaiting ...
Though Kotlin shows error when using Result as return type it was working good for us until we introduced coroutines.
Read more >
Hey guys There is a problem about kotlin coroutine I used ko
CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[TestCoroutineDispatcher[currentTime=0ms, queued=0], ...
Read more >
mockk-io/Lobby - Gitter
(i'm looking at this: https://stackoverflow.com/a/63655948/1454). Ugo Delle Donne. @udelledo ... resumeCancellableWith(DispatchedContinuation.kt:305)
Read more >
commonMain.Dispatched.kt Maven / Gradle / Ivy - Download JAR files
private inline fun DispatchedContinuation<*>. ... continuation for execution to avoid stack overflow _state = contState resumeMode = mode eventLoop.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found