Open dkhalanskyjb opened 2 months ago
It's unclear what to do in this scenario, though. Here are some options:
handleCoroutineException
. We don't call it a mechanism of last-resort exception propagation for nothing.Executor.asCoroutineDispatcher
tries cancelling the task and redispatching it to Dispatchers.IO
if the executor rejected it. We can't do literally that in common code, as there is no Dispatchers.IO
on platforms with no threads, but if there are no threads, we can just use DefaultExecutor
. The problem is, what if finalizers contain some code that must run on a specific thread? If Dispatchers.Main
fails, it's usually a contract violation to try to run its code on Dispatchers.IO
.
Describe the bug
During the review of https://github.com/Kotlin/kotlinx.coroutines/pull/4181, it became evident that we don't properly handle failures in coroutine dispatchers, and this can surface in ways other than just strange-looking exceptions.
Provide a Reproducer
This code will hang after printing
This code runs...
, as the launched coroutine never finishes.