Skip to content

Commit 927e973

Browse files
authored
PipeWriter.UnflushedBytes long property wraps to negative numbers after int.MaxValue (#115978)
* PipeWriter.UnflushedBytes long property wraps to negative numbers after int.MaxValue * forgotten * play the test is memory abundant envs * fix remarks round 1 * delete trailing line * change test name
1 parent 81cff29 commit 927e973

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal sealed class StreamPipeWriter : PipeWriter
2020
private BufferSegment? _tail;
2121
private Memory<byte> _tailMemory;
2222
private int _tailBytesBuffered;
23-
private int _bytesBuffered;
23+
private long _bytesBuffered;
2424

2525
private readonly MemoryPool<byte>? _pool;
2626
private readonly int _maxPooledBufferSize;

src/libraries/System.IO.Pipelines/tests/PipeWriterTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,5 +360,20 @@ public async Task GetMemoryFlushWithACompletedReaderNoops()
360360
Assert.Equal(0, pool.CurrentlyRentedBlocks);
361361
Assert.Equal(0, Pipe.Writer.UnflushedBytes);
362362
}
363+
364+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser), nameof(PlatformDetection.Is64BitProcess))]
365+
public void UnflushedBytes_HandlesLargeValues()
366+
{
367+
PipeWriter writer = PipeWriter.Create(Stream.Null);
368+
int bufferSize = 10000;
369+
370+
while (writer.UnflushedBytes >= 0 && writer.UnflushedBytes <= int.MaxValue)
371+
{
372+
writer.GetMemory(bufferSize);
373+
writer.Advance(bufferSize);
374+
}
375+
376+
Assert.Equal(2147490000, writer.UnflushedBytes);
377+
}
363378
}
364379
}

0 commit comments

Comments
 (0)