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

Commit

Permalink
Always complete RequestBodyPipe.Reader (#1893)
Browse files Browse the repository at this point in the history
* Disable test that leaks blocks in debug builds
* Move some test helpers
  • Loading branch information
halter73 authored Jun 12, 2017
1 parent 31e5dfd commit d879518
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,9 @@ public override async Task ProcessRequestsAsync()
TimeoutControl.SetTimeout(Constants.RequestBodyDrainTimeout.Ticks, TimeoutAction.SendTimeoutResponse);
await messageBody.ConsumeAsync();
TimeoutControl.CancelTimeout();

// At this point both the request body pipe reader and writer should be completed.
RequestBodyPipe.Reset();
}
else
{
RequestBodyPipe.Reader.Complete();
messageBody.Cancel();
Input.CancelPendingRead();
}
Expand Down Expand Up @@ -201,6 +197,14 @@ public override async Task ProcessRequestsAsync()
// StopStreams should be called before the end of the "if (!_requestProcessingStopping)" block
// to ensure InitializeStreams has been called.
StopStreams();

if (HasStartedConsumingRequestBody)
{
RequestBodyPipe.Reader.Complete();

// At this point both the request body pipe reader and writer should be completed.
RequestBodyPipe.Reset();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,12 @@ public void Cancel()
{
TryInit();

try
ReadResult result;
do
{
ReadResult result;
do
{
result = await _context.RequestBodyPipe.Reader.ReadAsync();
_context.RequestBodyPipe.Reader.Advance(result.Buffer.End);
} while (!result.IsCompleted);
}
finally
{
_context.RequestBodyPipe.Reader.Complete();
}
result = await _context.RequestBodyPipe.Reader.ReadAsync();
_context.RequestBodyPipe.Reader.Advance(result.Buffer.End);
} while (!result.IsCompleted);
}

protected void Copy(ReadableBuffer readableBuffer, WritableBuffer writableBuffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public async Task CopyToAsyncDoesNotCompletePipeReader()
}

[Fact]
public async Task ConsumeAsyncCompletesPipeReader()
public async Task ConsumeAsyncConsumesAllRemainingInput()
{
using (var input = new TestInput())
{
Expand All @@ -359,7 +359,7 @@ public async Task ConsumeAsyncCompletesPipeReader()

await body.ConsumeAsync();

await Assert.ThrowsAsync<InvalidOperationException>(async () => await body.ReadAsync(new ArraySegment<byte>(new byte[1])));
Assert.Equal(0, await body.ReadAsync(new ArraySegment<byte>(new byte[1])));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
{
public class FrameConnectionManagerTests
{

// This test causes MemoryPoolBlocks to be finalized which in turn causes an assert failure in debug builds.
#if !DEBUG
[ConditionalFact]
[NoDebuggerCondition]
public async Task CriticalErrorLoggedIfApplicationDoesntComplete()
Expand Down Expand Up @@ -65,6 +66,7 @@ public async Task CriticalErrorLoggedIfApplicationDoesntComplete()
Assert.True(logWaitAttempts < 10);
}
}
#endif

private class NoDebuggerConditionAttribute : Attribute, ITestCondition
{
Expand Down

0 comments on commit d879518

Please sign in to comment.