icerpc / icerpc-csharp

A C# RPC framework built for QUIC, with bidirectional streaming, first-class async/await, and Protobuf support.
https://docs.icerpc.dev
Apache License 2.0
107 stars 13 forks source link

icerpc: invocation cancellation and disposal #3163

Closed bernardnormier closed 1 year ago

bernardnormier commented 1 year ago

As a follow up to #3134, it would be make sense to refactor IceRpcProtocolConnection so that DisposeAsync waits for _streamsClosed before disposing its transport connection.

_streamsClosed is completed when _shutdownTask is not null and _streamCount is 0.

If we do that, InvokeAsync cannot be "killed" by an ODE, since DisposeAsync waits for the stream closure. This makes InvokeAsync a bit simpler as a result.

Currently (before #3134), we can't do that because a Slic stream write can hang forever (until the Slic connection is disposed).

bernardnormier commented 1 year ago

While we can probably improve the code, I don't think DisposeAsync can wait for _streamsClosed to complete before disposing the underlying connection.

Example: an invocation got a response with a stream, and the application code is slowly reading this PipeReader (or doing other stuff while it's supposed to read the PipeReader). This payload/PipeReader corresponds to the stream Input and there is no way to speed-up its completion (stream.ReadsClosed) other than disposing the underlying connection. Am I missing something?