Closed
Description
Description
(I edited this issue when I noticed the bug did not affected only ReadAtLeastAsync, original title was 'Pipe.ReadAtLeastAsync return with less bytes than asked.')
Calling Pipe.Writer.WriteAsync after Pipe.Writer.Advance flush truncated data to the PipeReader.
I initially found this bug because ReadAtLeastAsync returned me a 12 bytes buffer, when I asked for 26.
Reproduction Steps
Edit:
[Test]
public async Task ReadAtLeastAsync_works()
{
Pipe pipe = new Pipe(new PipeOptions(minimumSegmentSize: 1));
Task<ReadResult> resTask = pipe.Reader.ReadAtLeastAsync( 26 ).AsTask();
pipe.Writer.GetSpan( 14 );
pipe.Writer.Advance( 14 );
await pipe.Writer.WriteAsync( new byte[12] );
ReadResult res = await resTask;
res.Buffer.Length.Should().Be( 26 ); //fails
}
Expected behavior
Data written is not overwritten.
Actual behavior
Only 12 bytes are returned. The first write is partially overwritten.
Regression?
The reproduction does not show the bug on version 4.5.4.
Known Workarounds
Call FlushAsync before calling WriteAsync if you did Advance() before.
Configuration
N/A.