Skip to content Skip to sidebar Skip to footer

How To Recover The Coroutine's True Call Trace?

This is a painfully familiar problem to anyone working with async APIs: when your call encounters a failure, the async library's private thread detects it, creates an exception obj

Solution 1:

First off all the feature is broken at the moment. If the bug is fixed I would try System.setProperty(DEBUG_PROPERTY_NAME,DEBUG_PROPERTY_VALUE_ON).

Solution 2:

I faced the same problem. The Kotlin coroutine debug library didn't help me in any way. Therefore, after studying the implementation of coroutines, I wrote my own solution based on bytecode generation and MethodHandle API. It supports JVM 1.8 and Android API 26 or higher. I called it Stacktrace-decoroutinator.

The reason why the stacktrace is lost is that when the coroutine wakes up, only the last method of its call stack is called.

My library replaces the coroutine awakening implementation. It generates classes at runtime with names that match the entire coroutine call stack. These classes don't do anything except call each other in the coroutine call stack sequence.

Thus, if the coroutine throws an exception, they mimic the real call stack of the coroutine during the creation of the exception stacktrace.

Solution 3:

Solution 4:

Just found a github issue related to this:

Stacktrace recovery ( https://github.com/Kotlin/kotlinx.coroutines/pull/792 ) and the related doc ( https://github.com/Kotlin/kotlinx.coroutines/blob/master/docs/debugging.md )

Without the caller site stacktrace, coroutine debugging is indeed painful. Hope that the "debug mode" can help. Will try and see.

Post a Comment for "How To Recover The Coroutine's True Call Trace?"