so the above issue is actually rooted in using `Co...
# multiplatform
k
so the above issue is actually rooted in using
CoroutineWorker.execute
with
CompletableDeferred
. anyone have an idea why completing the deferred might deadlock when used from
execute
?
b
do you have a code sample?
k
i can distill it down into a basic example
Copy code
@Test fun testSomething() = runBlocking {
    val deferred = CompletableDeferred<Unit>()
    CoroutineWorker.execute {
        ...
        deferred.complete(Unit)
    }
    deferred.await()
}
it deadlocks on
deferred.complete
b
is this using native mt branch or something?
k
no
b
that's going to freeze
deferred
then, which could do bad things
there's probably internal state you're freezing
it may not be deadlocking as much as crashing on a bg thread and dying silently
k
any problems from that would throw an exception, would it not?
b
and then your main thread never finishes waiting on the deferred
yes but exceptions in Worker do not crash the app
they just log
k
hmmm
b
that's why CoroutineWorker has a special mechanism for capturing Worker exceptions so that you can manually crash, if that's what you want
k
i've always gotten a stack trace when i've had issues with freezing in the past
b
you won't get the exception when you freeze, you'll get it later in the background when you try to complete the deferred
k
understood
logs might show the exception, assuming my guess is correct
k
i'll give it a shot
👍 1
b
Best documentation I can find about worker uncaught exceptions is just the param for Worker.start: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.native.concurrent/-worker/start.html
IIRC, it was just something we observed when testing things for our first App Store release
k
the handler is not receiving an exception in this case
well, whatever the actual root cause is, seems like I am going to be rolling my own kind of Deferred to fix this, so I might as well just do that
👍 1
so strange, now that's fixed (something about
COROUTINE_SUSPENDED
seems to cause the dead lock), but now I have the same behavior with
Semaphore
b
What's COROUTINE_SUSPENDED?
Semaphore also can't be frozen, if you mean the one from coroutines lib
k
it's a special value used with
suspendCoroutine
i replaced semaphore with the same class I used in place of deferred
now it's all working
b
Huh 👌
k
¯\_(ツ)_/¯