Is there a way to debug `Mutex` deadlocks caused b...
# coroutines
m
Is there a way to debug
Mutex
deadlocks caused by recursion?
o
there's the
owner
parameter, you can pass that and it will throw if you re-lock with the same
owner
m
Yes, but that doesn’t help me with accidental recursion?
o
depends on your choice of
owner
I guess
if you were to store an element in the coroutine context, it would still be there post-recursion, so you could initialize e.g.
coroutineContext[MyDebugElement] = coroutineContext[MyDebugElement] ?: Any()
, and then pass that as the
owner
. if you recurse, then you'll use the same unique object and it'll throw
m
Hmm, it wouldn’t be inherited by lauched coroutines I presume?
o
no, it wouldn't
l
It'd actually, unless it is replaced. That's how it works for all coroutineContext elements, like
ContinuationInterceptor
(
CoroutineDispatcher
implements it).
o
oh, well I guess it depends on how you launch
if you do it in
coroutineScope {}
or similar then yes
but if you're legitimately switching to a new context via a separate scope, then no