Skip to content

Commit

Permalink
Merge pull request dotnet#1 from shutdown256/shutdown256-issue-37802
Browse files Browse the repository at this point in the history
fix CopyToAsyncCore - cancellation and infinite loop
  • Loading branch information
shutdown256 authored May 21, 2019
2 parents 0f22cd0 + 360e535 commit e40fcb6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/System.IO.Pipelines/src/System/IO/Pipelines/PipeReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ private async Task CopyToAsyncCore(Stream destination, CancellationToken cancell
{
SequencePosition consumed = default;

ReadResult result = await ReadAsync(cancellationToken).ConfigureAwait(false);
try
{
ReadResult result = await ReadAsync(cancellationToken).ConfigureAwait(false);
ReadOnlySequence<byte> buffer = result.Buffer;
SequencePosition position = buffer.Start;

Expand All @@ -130,7 +130,12 @@ private async Task CopyToAsyncCore(Stream destination, CancellationToken cancell

consumed = position;
}


if (consumed.Equals(default(SequencePosition))
{
consumed = buffer.End;
}

if (result.IsCompleted)
{
break;
Expand Down

0 comments on commit e40fcb6

Please sign in to comment.