diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs index b5f6006cf220..57aa56bc53d6 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs @@ -3588,6 +3588,7 @@ await WaitForConnectionErrorAsync(ignoreNonGoAway [Fact] public async Task RST_STREAM_IncompleteRequest_AdditionalResetFrame_IgnoreAdditionalReset() { + var abortedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var headers = new[] @@ -3596,13 +3597,20 @@ public async Task RST_STREAM_IncompleteRequest_AdditionalResetFrame_IgnoreAdditi new KeyValuePair(InternalHeaderNames.Path, "/"), new KeyValuePair(InternalHeaderNames.Scheme, "http"), }; - await InitializeConnectionAsync(context => tcs.Task); + await InitializeConnectionAsync(context => + { + context.RequestAborted.Register(() => abortedTcs.TrySetResult()); + return tcs.Task; + }); await StartStreamAsync(1, headers, endStream: false); await SendDataAsync(1, new byte[1], endStream: false); await SendRstStreamAsync(1); await SendRstStreamAsync(1); - tcs.TrySetResult(); + + await abortedTcs.Task; + + tcs.TrySetResult(); // Don't let the response start until after the request aborts await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);