-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Exception inside async {} is logged by uncaught exception handler #893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hmm, seems similar to #875 |
It happens so by design. So when You can read more about this paritucular design decision in this blog post: https://medium.com/@elizarov/futures-cancellation-and-coroutines-b5ce9c3ede3a |
@elizarov why does an external coroutine being cancelled cause the crash inside the |
@elizarov that example prints nothing to my console... |
I see... That is indeed the question... let me dig deeper. |
I've minimized it to this:
|
Your new example does not exhibit the behavior (on my machine), but if I adjust the timing a bit, it does: fun main(args: Array<String>) {
val deferred = GlobalScope.async {
delay(1000)
throw Exception("boom")
}
val job = GlobalScope.launch(Dispatchers.Unconfined) {
try {
deferred.await()
} catch (e: Exception) {
println("error awaiting: $e")
}
}
job.cancel()
Thread.sleep(3000)
} |
Ok. Now I'm getting to it. So, essentially it is the same problem as explained in #830, so switching to PR #896 branch also fixes this problem. However, this particular problem that you've reported has deeper roots and it consistently reproduces even if cancel/fail do not race with each other. This deeper problem problem stems from the fact that |
Thank you for looking into it. |
Thank you for reporting! As you can see, we still don't have all corner cases covered by test, so all those "something strange going on" observations are very important. |
I can't find anything in the docs to explain why the following is or isn't a bug:
Results in:
The uncaught exception handler prints the exception after the 5 second delay expires whether or not the second call to
await()
is made.Without the cancellation it behaves as expected:
The text was updated successfully, but these errors were encountered: