-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Flow.retry() and cancellation #1122
Comments
I agree that this behavior is counter-intuitive and should be fixed.
|
Would checking the collecting job's |
No, because it is prone to check-and-act data races. |
Are there plans to make the underpinnings of this check public API that could be used from operators defined outside of kotlinx.coroutines? |
Yes. We are thinking on how to generalize this solution. |
The implementation of
Flow.retry()
differentiates between upstream exceptions that should potentially trigger a retry and downstream exceptions that should pass through by wrapping the call toemit
. This has unexpected behavior in the case of cancellation when the operation is suspended on a call that is technically upstream.Consider:
The above can potentially never join.
retry
attempts to start a newcollect
from upstream after catching theCancellationException
that did not originate from the inneremit
call withinretry
's implementation, and the newcollect
on the upstream source quickly fails because the calling job is cancelling. Retry dutifully catches theCancellationException
again and repeats the process.The problem can be avoided by explicitly allowing
CancellationException
to pass through via the predicate, e.g.reader.retry { it !is CancellationException }
though perhaps this should be the default behavior.The text was updated successfully, but these errors were encountered: