diff --git a/src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj b/src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj
index 1d743c99ad2671..ff95c1648dad9c 100644
--- a/src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj
+++ b/src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj
@@ -9,7 +9,8 @@ Commonly Used Types:
System.IO.Pipelines.Pipe
System.IO.Pipelines.PipeWriter
System.IO.Pipelines.PipeReader
- 1
+ true
+ 2
source)
}
// We filled the segment
- _writingHead.End += writable;
+ _writingHead.End += _writingHeadBytesBuffered;
_writingHeadBytesBuffered = 0;
// This is optimized to use pooled memory. That's why we pass 0 instead of
diff --git a/src/libraries/System.IO.Pipelines/tests/PipeLengthTests.cs b/src/libraries/System.IO.Pipelines/tests/PipeLengthTests.cs
index fcf9d7af55b053..fd9fc83833a8b1 100644
--- a/src/libraries/System.IO.Pipelines/tests/PipeLengthTests.cs
+++ b/src/libraries/System.IO.Pipelines/tests/PipeLengthTests.cs
@@ -277,5 +277,19 @@ public async Task NullExaminedAndConsumedNoops()
ReadResult result = await _pipe.Reader.ReadAsync();
_pipe.Reader.AdvanceTo(default, default);
}
+
+ [Fact]
+ public async Task AdvanceFollowedByWriteAsyncTest()
+ {
+ Memory buffer = new byte[26];
+ Pipe pipe = new(new PipeOptions(minimumSegmentSize: 1));
+
+ var mem = pipe.Writer.GetMemory(14)[..14];
+ buffer[..14].CopyTo(mem);
+ pipe.Writer.Advance(14);
+ await pipe.Writer.WriteAsync(buffer[14..]);
+ ReadResult res = await pipe.Reader.ReadAsync();
+ Assert.Equal(res.Buffer.Length, buffer.Length);
+ }
}
}