Always complete RequestBodyPipe.Reader (#1893)
* Disable test that leaks blocks in debug builds * Move some test helpers
This commit is contained in:
parent
31e5dfdcf0
commit
d879518a18
|
|
@ -163,13 +163,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
TimeoutControl.SetTimeout(Constants.RequestBodyDrainTimeout.Ticks, TimeoutAction.SendTimeoutResponse);
|
TimeoutControl.SetTimeout(Constants.RequestBodyDrainTimeout.Ticks, TimeoutAction.SendTimeoutResponse);
|
||||||
await messageBody.ConsumeAsync();
|
await messageBody.ConsumeAsync();
|
||||||
TimeoutControl.CancelTimeout();
|
TimeoutControl.CancelTimeout();
|
||||||
|
|
||||||
// At this point both the request body pipe reader and writer should be completed.
|
|
||||||
RequestBodyPipe.Reset();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RequestBodyPipe.Reader.Complete();
|
|
||||||
messageBody.Cancel();
|
messageBody.Cancel();
|
||||||
Input.CancelPendingRead();
|
Input.CancelPendingRead();
|
||||||
}
|
}
|
||||||
|
|
@ -201,6 +197,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
// StopStreams should be called before the end of the "if (!_requestProcessingStopping)" block
|
// StopStreams should be called before the end of the "if (!_requestProcessingStopping)" block
|
||||||
// to ensure InitializeStreams has been called.
|
// to ensure InitializeStreams has been called.
|
||||||
StopStreams();
|
StopStreams();
|
||||||
|
|
||||||
|
if (HasStartedConsumingRequestBody)
|
||||||
|
{
|
||||||
|
RequestBodyPipe.Reader.Complete();
|
||||||
|
|
||||||
|
// At this point both the request body pipe reader and writer should be completed.
|
||||||
|
RequestBodyPipe.Reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -204,19 +204,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
{
|
{
|
||||||
TryInit();
|
TryInit();
|
||||||
|
|
||||||
try
|
ReadResult result;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
ReadResult result;
|
result = await _context.RequestBodyPipe.Reader.ReadAsync();
|
||||||
do
|
_context.RequestBodyPipe.Reader.Advance(result.Buffer.End);
|
||||||
{
|
} while (!result.IsCompleted);
|
||||||
result = await _context.RequestBodyPipe.Reader.ReadAsync();
|
|
||||||
_context.RequestBodyPipe.Reader.Advance(result.Buffer.End);
|
|
||||||
} while (!result.IsCompleted);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_context.RequestBodyPipe.Reader.Complete();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Copy(ReadableBuffer readableBuffer, WritableBuffer writableBuffer)
|
protected void Copy(ReadableBuffer readableBuffer, WritableBuffer writableBuffer)
|
||||||
|
|
|
||||||
|
|
@ -349,7 +349,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ConsumeAsyncCompletesPipeReader()
|
public async Task ConsumeAsyncConsumesAllRemainingInput()
|
||||||
{
|
{
|
||||||
using (var input = new TestInput())
|
using (var input = new TestInput())
|
||||||
{
|
{
|
||||||
|
|
@ -359,7 +359,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||||
|
|
||||||
await body.ConsumeAsync();
|
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])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class FrameConnectionManagerTests
|
public class FrameConnectionManagerTests
|
||||||
{
|
{
|
||||||
|
// This test causes MemoryPoolBlocks to be finalized which in turn causes an assert failure in debug builds.
|
||||||
|
#if !DEBUG
|
||||||
[ConditionalFact]
|
[ConditionalFact]
|
||||||
[NoDebuggerCondition]
|
[NoDebuggerCondition]
|
||||||
public async Task CriticalErrorLoggedIfApplicationDoesntComplete()
|
public async Task CriticalErrorLoggedIfApplicationDoesntComplete()
|
||||||
|
|
@ -65,6 +66,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
Assert.True(logWaitAttempts < 10);
|
Assert.True(logWaitAttempts < 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
private class NoDebuggerConditionAttribute : Attribute, ITestCondition
|
private class NoDebuggerConditionAttribute : Attribute, ITestCondition
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue