-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Flow<T>.first operator throws NoSuchElementException where CancellationException must be thrown #2051
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
qwwdfsad
added a commit
that referenced
this issue
May 25, 2020
…erator. It fixes two problems: * NoSuchElementException can be thrown during cancellation sequence (see FirstJvmTest that reproduces this problem with explanation) * Cancellation can be accidentally suppressed and flow activity can be prolonged Fixes #2051
Thanks for the report with self-contained repro! Fixed using a more future-proof approach with checking the identity of the caught exception |
qwwdfsad
added a commit
that referenced
this issue
May 25, 2020
…erator. It fixes two problems: * NoSuchElementException can be thrown during cancellation sequence (see FirstJvmTest that reproduces this problem with explanation) * Cancellation can be accidentally suppressed and flow activity can be prolonged Fixes #2051
@qwwdfsad, sounds good. Thanks! |
recheej
pushed a commit
to recheej/kotlinx.coroutines
that referenced
this issue
Dec 28, 2020
Kotlin#2057) It fixes two problems: * NoSuchElementException can be thrown during cancellation sequence (see FirstJvmTest that reproduces this problem with explanation) * Cancellation can be accidentally suppressed and flow activity can be prolonged Fixes Kotlin#2051
denyshorman
added a commit
to denyshorman/experimental-asset-trader
that referenced
this issue
May 16, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Consider the following test
It is expected to take N elements and correctly finish the coroutine but actually it throws
NoSuchElementException
.It happens because
AbortFlowException
, that is used inside first operator, extendsCancellationException
and if upstream flow is cancelled before callingcollect
, it must throwCancellationException
instead ofNoSuchElementException
.Test passes when
AbortFlowException
is extended fromThrowable
This issue is relevant for firstOrNull operator and, perhaps, other similar ones.
The text was updated successfully, but these errors were encountered: