Skip to content

Coroutines Stacktrace Recovery trims the suspend call stack #4398

@andriybobchuk

Description

@andriybobchuk

Describe the bug

I enabled stack trace recovery with
System.setProperty("kotlinx.coroutines.stacktrace.recovery", "true")
in my project's Application class onCreate, but it does not seem to work for me no matter what I do.

For example this code:

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        runBlocking {
            callerFunction1()
        }
     }

fun callerFunction1() {
        CoroutineScope(Dispatchers.Main + CoroutineName("Caller1")).launch {
            intermediateFunction1()
        }
}

suspend fun intermediateFunction1() {
        delay(100) 
        intermediateFunction3()
    }

suspend fun intermediateFunction2() {
        delay(100)
        crashFunction()
    }

will trim the stack trace only to crashFunction call without any callers info.

What I tried:

  • Using Coroutine ExceptionHandler
  • Using try-catch at the top level
  • Using my CustomException which implements CopiableThrowable
  • Using other types of exception like IllegalStateException

Environment

  • Android
  • Standard debug build - no Proguard or R8
  • kotlin 2.0.0
  • coroutinesVersion 1.8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions