dotnet/Nerdbank.Streams

Avoid first chance exceptions with one-way pipes over MultiplexingStream

AArnott opened this issue · 0 comments

From @sharwell:

LinkToAsync could do a better job of handling one-way pipes passed as arguments. Currently it ends up calling LinkToAsync on a completed PipeReader and relies on exception handling to deal with it internally. This results in two first chance exceptions for every PipeWriter passed as an argument.

https://github.com/AArnott/Nerdbank.Streams/blob/855f6afae3b2af5c558cca96ca41216cab363474/src/Nerdbank.Streams/MultiplexingStream.Channel.cs#L617

channelOptions.ExistingPipe.Input might be already completed there, which throws once here:

https://github.com/AArnott/Nerdbank.Streams/blob/5f56226eacf44ae11bf4781ab8f41db6e1b05d33/src/Nerdbank.Streams/PipeExtensions.cs#L404

and once here:

https://github.com/AArnott/Nerdbank.Streams/blob/855f6afae3b2af5c558cca96ca41216cab363474/src/Nerdbank.Streams/MultiplexingStream.Channel.cs#L701

it's at least possible to detect CompletedPipeReader