kotlinx.coroutines icon indicating copy to clipboard operation
kotlinx.coroutines copied to clipboard

CoroutineScope.future() may trigger global exception handler on cancellation

Open frost13it opened this issue 3 years ago • 1 comments
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

frost13it avatar Sep 13 '22 13:09 frost13it

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.

frost13it avatar Sep 13 '22 13:09 frost13it