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
flatMapLatest + combine + first leads to execution while cancelled #4034
Comments
Could not reproduce with coroutines 1.7.3 using Android instrumented tests. The output for me is:
Due to cancellation, the "After first" |
Yes, that's right. It does not repro in an instrumented test for us either. But it does when you put that code in |
Here is a complete example. Run it and see the output in logcat. |
Ok, reproduced. |
@dkhalanskyjb Can you remove the "waiting for clarification" label so it doesn't get auto closed? |
Describe the bug
Firstly, it's possible this is expected behavior but it certainly doesn't seem that way.
We have a flow that we collect using
first()
. This flow is a combination of multiple upstream flows but they all emit their items synchronously. The downstream flow limits the number of emissions to a single element then usesawaitCompletion()
to avoid terminating the flow. This is the flow we callfirst()
on.Under some circumstances, we are seeing the
first()
call resuming after the scope has been cancelled which is causing a crash for us.If either the
flatMapLatest
orcombine
is removed, the code behaves as expected, althoughfirst()
never resumes.I know there are no real guarantees that code won't be running while canceled. But there are few things that makes me think that this doesn't apply in this case:
Provide a Reproducer
This reproduces it on an Android device, but it's possible it can reproed on the JVM too.
I expect this to print:
Instead I'm seeing this:
The text was updated successfully, but these errors were encountered: