kotlinx.coroutines
kotlinx.coroutines copied to clipboard
CoroutineScope.future() may trigger global exception handler on cancellation
trafficstars
Expected behavior
future coroutine builder delivers all errors via the returned object, just like async.
Actual behavior
future coroutine builder can suddenly trigger global exception handler that may crash the application.
Sample code:
fun main() {
val future = GlobalScope.future {
error("foo")
}
future.cancel(true)
Thread.sleep(100)
}
Result:
Exception in thread "DefaultDispatcher-worker-1" java.lang.IllegalStateException: foo
I believe CompletableFutureCorotine should not attempt to handle the exception in any other way than completing the returned CompletableFuture. For now, this is not the case.