diff --git a/src/libraries/System.IO.Pipelines/Directory.Build.props b/src/libraries/System.IO.Pipelines/Directory.Build.props
index 0daa67b02c97b..81ab65eae172c 100644
--- a/src/libraries/System.IO.Pipelines/Directory.Build.props
+++ b/src/libraries/System.IO.Pipelines/Directory.Build.props
@@ -2,7 +2,7 @@
Open
- 1
+ 2
5.0.0.1
diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.cs
index f90ac5b8a9b9f..0149c04051d91 100644
--- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.cs
+++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.cs
@@ -1011,7 +1011,7 @@ private void WriteMultiSegment(ReadOnlySpan 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 fcf9d7af55b05..fd9fc83833a8b 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);
+ }
}
}
diff --git a/src/libraries/libraries-packages.proj b/src/libraries/libraries-packages.proj
index 87660e3c2483c..00d67ec988127 100644
--- a/src/libraries/libraries-packages.proj
+++ b/src/libraries/libraries-packages.proj
@@ -18,6 +18,7 @@
+