Skip to content
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

Dispose the gRPC call underlying a Read if the read is only partially consumed #234

Merged
merged 1 commit into from
Dec 12, 2022

Conversation

timothycoleman
Copy link
Contributor

@timothycoleman timothycoleman commented Dec 9, 2022

Fixed: Dispose the gRPC call underlying a Read if the read is only partially consumed

e.g. when early returning from an await foreach or calling .First().

The IAsyncEnumerable is disposed as before, but now that causes the cancellation of the ResponseStream read, so PumpMessages completes and the call is disposed.

The CancellationTokenSource need not be disposed because it is always cancelled (That is, as long as the user makes any attempt to consume the read - if they don't then the call remains open as before)

Note, I did attempt to remove the channel, but the ReadState task is populated proactively, without the user needing to start consuming the read, so simply having IAsyncEnumerables isn't so straight forward.

Fixes: #219

thefringeninja
thefringeninja previously approved these changes Dec 9, 2022
… consumed

e.g. when early returning from an await foreach or calling .First().

The IAsyncEnumerable is disposed as before, but now that causes the cancellation of the ResponseStream read, so PumpMessages completes and the call is disposed.

The CancellationTokenSource need not be disposed because it is always cancelled (That is, as long as the user makes any attempt to consume the read - if they don't then
the call remains open as before)
@timothycoleman
Copy link
Contributor Author

Made the same fix for $all reads - thanks @pvanbuijtene for pointing it out

@thefringeninja thefringeninja merged commit ba8d821 into master Dec 12, 2022
@thefringeninja thefringeninja deleted the dispose-partially-consumed-reads branch December 12, 2022 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

22.0.0 leaves read calls open if partially consumed
3 participants