-
Notifications
You must be signed in to change notification settings - Fork 1.9k
ClosedSendChannelException confusing (actor should report failures) #422
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
@Khang-NT How are you running this code? It looks like the exception is swalled by
And running this code I clearly see |
Hi @elizarov, you are correct. My assumption was wrong, it's swallowed by val myActor = actor<Int> {
throws RuntimeException();
// an exception happen here, it causes the actor channel to be closed
};
fun doSomeWork() {
// here is very complicated
// some like call library method -> library callback
// -> invoke offer() on this callback (all are synchronously).
myActor.offer(0);
}
val aChannel = Channel<Int>(CONFLATED)
launch(myCoroutineContext) {
aChannel.consumeEach {
doSomeWork()
}
}
fun onSomeEvent() {
aChannel.offer(0);
// my app crashed here: aChannel was closed for send
}
What you will do to debug? I made a lot of wrongs assumption, and only find out the line val myActor = actor<Int> {
consumeEach {
throw MyException("useful stacktrace");
}
}
Maybe this is my bad, cuz I very doubt about how exception was propagated. |
That is actually a bug. |
Actors already behave like launch (#368)
Note that it was fixed in latest release (#368), so it's worth to update |
Lets see following snippet code:
Imagine what happen?
With my vision when read this code, I will think that the program should crash because
channelB
was closed but I invokeoffer()
.But It didn't crash. Because
ClosedSendChannelException
is swallowed bychannelA.iterator()
.It is kind of bug.
The text was updated successfully, but these errors were encountered: