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.

Stacktrace recovery doesn't work for suspend main

See original GitHub issue

I took the example https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/master/kotlinx-coroutines-debug/test/RecoveryExample.kt and add at line 16 a println("${Thread.currentThread().name}"), so I get

package example

import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async

object PublicApiImplementation : CoroutineScope by CoroutineScope(CoroutineName("Example")) {

    private fun doWork(): Int {
        error("Internal invariant failed")
    }

    private fun asynchronousWork(): Int {
        println("${Thread.currentThread().name}")
        return doWork() + 1
    }

    public suspend fun awaitAsynchronousWorkInMainThread() {
        val task = async(Dispatchers.Default) {
            asynchronousWork()
        }

        task.await()
    }
}

suspend fun main() {
    // Try to switch debug mode on and off to see the difference
    PublicApiImplementation.awaitAsynchronousWorkInMainThread()
}

I run it with

  1. -ea
  2. -Dkotlinx.coroutines.debug -Dkotlinx.coroutines.stacktrace.recovery=true
  3. -Dkotlinx.coroutines.debug

I never get an recovered stacktrace. How ever I got DefaultDispatcher-worker-1 @Example#1 so -Dkotlinx.coroutines.debug seems to work.

What does I’m missing? Here my version kotlin 1.3.41 coroutines.version 1.2.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
qwwdfsadcommented, Jul 16, 2019

As a workaround, you can use fun main() = runBlocking { ... } instead of suspend fun main()

0reactions
opensource21commented, Jul 16, 2019

If you clone https://gitlab.com/ppiag/zulipbot, rename application.properties.sample to application.properties and replace zulip.url=https://####.zulipchat.com with zulip.url=https://www.zulipchat.com and start BotRunner , I guess you have a different situation with ktor and it doesn’t work. Unfortunately it’s not so easy to debug 😦

Any idea when 1.3 will be released or a beta for a test?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stack trace recovery #74 - Kotlin/kotlinx.coroutines - GitHub
As you can see, named suspending functions now execute directly in the the correspondingly named functions on JVM, so the top of the...
Read more >
Kotlin coroutines stack trace problem - Libraries
I called it Stacktrace-decoroutinator. My library replaces the coroutine awakening implementation. It generates classes at runtime with names ...
Read more >
Kotlin coroutines crash with no helpful stacktrace
I messed up when asking this question and put the emphasis on wrong things. So I'm removing the "retrofit" tag. It turns out...
Read more >
Kotlin coroutines stack trace issue - DEV Community ‍ ‍
invokeSuspend(main.kt) at kotlin.coroutines.jvm.internal. ... I understand that the stack trace recovery mechanics only work for the case ...
Read more >
How to rescue a broken stack trace: Recovering the EBP chain
What happened is that the EBP chain got broken, and the debugger can't walk the stack any further. If the code was compiled...
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