Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ public override void Complete(Exception exception = null)

_isCompleted = true;

_internalTokenSource?.Dispose();

FlushInternal();

_internalTokenSource?.Dispose();

if (!_leaveOpen)
{
InnerStream.Dispose();
Expand All @@ -233,10 +233,10 @@ public override async ValueTask CompleteAsync(Exception exception = null)

_isCompleted = true;

_internalTokenSource?.Dispose();

await FlushAsyncInternal().ConfigureAwait(false);

_internalTokenSource?.Dispose();

if (!_leaveOpen)
{
#if netcoreapp
Expand Down
19 changes: 19 additions & 0 deletions src/System.IO.Pipelines/tests/StreamPipeWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ public async Task DataFlushedOnCompleteAsync()
Assert.Equal("Hello World", Encoding.ASCII.GetString(stream.ToArray()));
}

[Fact]
public async Task CompleteAsyncDoesNotThrowObjectDisposedException()
{
byte[] bytes = Encoding.ASCII.GetBytes("Hello World");
var stream = new MemoryStream();
PipeWriter writer = PipeWriter.Create(stream, new StreamPipeWriterOptions(leaveOpen: true));

await writer.FlushAsync();
bytes.AsSpan().CopyTo(writer.GetSpan(bytes.Length));
writer.Advance(bytes.Length);

Assert.Equal(0, stream.Length);

await writer.CompleteAsync();

Assert.Equal(bytes.Length, stream.Length);
Assert.Equal("Hello World", Encoding.ASCII.GetString(stream.ToArray()));
}

[Fact]
public async Task DataWrittenOnFlushAsync()
{
Expand Down