Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Make sure both sides of the loop close in AdaptedPipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfowl committed Aug 30, 2018
1 parent 5789ace commit 81edae2
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class AdaptedPipeline : IDuplexPipe, IDisposable
public AdaptedPipeline(Pipe inputPipe,
Pipe outputPipe,
ILogger log,
IDuplexPipe transport = null)
IDuplexPipe transport)
{
_transport = transport;
Input = inputPipe;
Expand Down Expand Up @@ -65,6 +65,11 @@ private async Task WriteOutputAsync(Stream stream)

try
{
if (result.IsCanceled)
{
break;
}

if (buffer.IsEmpty)
{
if (result.IsCompleted)
Expand Down Expand Up @@ -113,7 +118,10 @@ private async Task WriteOutputAsync(Stream stream)
{
Output.Reader.Complete();

_transport?.Output.Complete();
_transport.Output.Complete();

// Cancel any pending flushes due to back-pressure
Input.Writer.CancelPendingFlush();
}
}

Expand Down Expand Up @@ -151,7 +159,7 @@ private async Task ReadInputAsync(Stream stream)

var result = await Input.Writer.FlushAsync();

if (result.IsCompleted)
if (result.IsCompleted || result.IsCanceled)
{
break;
}
Expand All @@ -168,7 +176,10 @@ private async Task ReadInputAsync(Stream stream)

// The application could have ended the input pipe so complete
// the transport pipe as well
_transport?.Input.Complete();
_transport.Input.Complete();

// Cancel any pending reads from the application
Output.Reader.CancelPendingRead();
}
}

Expand Down

0 comments on commit 81edae2

Please sign in to comment.