Skip to content

Pipe.WriteAsync returns a completed FlushResult even when data is not written #51272

@manandre

Description

@manandre

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions