-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Stream.consumeAsFlow() finally block not getting called #1825
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
Do you have a self-contained reproducer, or a link to it from play.kotl.in? |
the collecting code lives here: https://github.com/trib3/leakycauldron/blob/master/graphql/src/main/kotlin/com/trib3/graphql/websocket/GraphQLWebSocketConsumer.kt#L103-L126 Even in our real service, it's hard to reproduce on demand, but a toy example that should demonstrate the same issue lives at https://github.com/trib3/example-cauldron-service/ ( flow gets defined at https://github.com/trib3/example-cauldron-service/blob/master/server/src/main/kotlin/com/trib3/example/server/graphql/Subscription.kt ). Using apollographql's websocket transport to connect and kick off a bunch of subscription queries, then closing those connections might be the best way to try to trigger it. |
It's not exactly a |
Self-contained repro (prints
|
…o ensure proper termination, including finally blocks and onCompletion operators Fixes #1825
Interesting. Agree that the |
It is fully safe. What about |
We're using
java.util.stream.Stream.consumeAsFlow()
to process a stream as a flow.our usage looked like:
Occasionally, it appears that the
finally { stream.close() }
block is not getting called (possibly on certain cancellation / error conditions?), resulting in connection leaks. However, it appears that if we add anonCompletion {}
to the returned flow, that block does get called even when the finally gets skipped:Have verified this by duplicating the
StreamFlow
class and adding logging to the finally block, as well as having logging in the.onCompletion
block above, and seen a few instances of the completion log firing without the finally log firing, but can't easily reproduce this (usually both fire).The text was updated successfully, but these errors were encountered: