EventStore / EventStore-Client-Dotnet

Dotnet Client SDK for the Event Store gRPC Client API written in C#
Other
140 stars 38 forks source link

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

Closed timothycoleman closed 1 year ago

timothycoleman commented 1 year ago

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: https://github.com/EventStore/EventStore-Client-Dotnet/issues/219

timothycoleman commented 1 year ago

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