When calling the WriteAsync method with some data on a Pipe, we can receive a completed FlushResult (IsCompleted = true) while data has not been actually written.
In Pipe.cs we can read at the beginning of the WriteAsync method:
if (_readerCompletion.IsCompletedOrThrow())
{
return new ValueTask<FlushResult>(new FlushResult(isCanceled: false, isCompleted: true));
}
This code prevents us from uselessly preparing data to be consumed by an already completed reader but, in the same time, it reuses a return contract (FlushResult) that is dedicated to a flush, so post-write, situation.
As a consequence, we have no means to discriminate whether the data has been consumed or not, what prevent us from fixing the PipeReader.CopyToAsync method as described in #51147 (comment)
/cc @davidfowl