My application is deadlocking in some conditions a...
# coroutines
f
My application is deadlocking in some conditions and I cant debug the reason. The code have some mutex and suspend functions. Could you provide some hint to debug coroutines with mutex and so on??
1
s
There was a KotlinConf talk on debugging coroutines, maybe it has some tips that can help:

https://youtu.be/QomoVqZSXP0

👀 1
f
ok, in the video he talks about add coroutine debug
Copy code
application {
    applicationDefaultJvmArgs = listOf("-Dkotlinx.coroutines.debug=on")
}
I am using Android Studio in multplatform project , I unable to enable that flag
e
there is an experimental DSL for the JVM run task in KMP, https://youtrack.jetbrains.com/issue/KT-50227
unfortunately it doesn't expose
jvmArgs
currently
in the meantime, you can
Copy code
tasks.named<JavaExec>("jvmRun") {
    jvmArgs("-Dkotlinx.coroutines.debug=on")
}
although for debugging it may be even more useful to
Copy code
enableAssertions = true
which kotlinx-coroutines-debug also picks up by default (assuming it's included in your runtime classpath of course)
l
Keep in mind that Mutex is not reentrant.
c
When you use Mutex, always specify the optional
owner
argument. Not only will it massively improve error messages, it will actually detect some deadlocks (the ones caused by mutex not being reentrant) and log them
f
hello, i found the deadlock and fix it. Thank so much for the help and tips