Fix flaky StreamPool_StreamIsInvalidState_DontReturnedToPool (#20433)

This commit is contained in:
James Newton-King 2020-04-03 08:23:13 +13:00 committed by GitHub
parent 5ac84db518
commit 53eaa8f106
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -41,10 +41,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
private bool _suffixSent;
private bool _streamEnded;
private bool _writerComplete;
private bool _disposed;
// Internal for testing
internal ValueTask _dataWriteProcessingTask;
internal bool _disposed;
/// <summary>The core logic for the IValueTaskSource implementation.</summary>
private ManualResetValueTaskSourceCore<FlushResult> _responseCompleteTaskSource = new ManualResetValueTaskSourceCore<FlushResult> { RunContinuationsAsynchronously = true }; // mutable struct, do not make this readonly

View File

@ -486,12 +486,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
withStreamId: 1);
await WaitForStreamErrorAsync(1, Http2ErrorCode.INTERNAL_ERROR, null);
// Ping will trigger the stream to be returned to the pool so we can assert it
await SendPingAsync(Http2PingFrameFlags.NONE);
await ExpectAsync(Http2FrameType.PING,
withLength: 8,
withFlags: (byte)Http2PingFrameFlags.ACK,
withStreamId: 0);
await PingUntilStreamDisposed(stream).DefaultTimeout();
// Stream is not returned to the pool
Assert.Equal(0, _connection.StreamPool.Count);
@ -500,6 +495,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
await output._dataWriteProcessingTask.DefaultTimeout();
await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);
async Task PingUntilStreamDisposed(Http2Stream stream)
{
var output = (Http2OutputProducer)stream.Output;
do
{
// Ping will trigger the stream to be returned to the pool so we can assert it
await SendPingAsync(Http2PingFrameFlags.NONE);
await ExpectAsync(Http2FrameType.PING,
withLength: 8,
withFlags: (byte)Http2PingFrameFlags.ACK,
withStreamId: 0);
} while (!output._disposed);
}
}
[Fact]