From 6c847a6ca8637b53814234d1fbcbbabaa68fbd13 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Mon, 9 Mar 2026 16:51:29 -0500 Subject: [PATCH 1/2] Fix race in RST_STREAM_IncompleteRequest_AdditionalResetFrame test Move tcs.TrySetResult() after StopConnectionAsync so the response handler stays blocked until the connection has stopped. This prevents response HEADERS from being written before the GOAWAY frame, which caused the test to intermittently fail with 'Expected: GOAWAY, Actual: HEADERS'. This is the same fix pattern applied in #65454 for the sibling AdditionalDataFrames and AdditionalTrailerFrames tests, and in #57450 for the AdditionalWindowUpdateFrame test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs index b5f6006cf220..874cbcd26dec 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs @@ -3602,10 +3602,11 @@ public async Task RST_STREAM_IncompleteRequest_AdditionalResetFrame_IgnoreAdditi await SendDataAsync(1, new byte[1], endStream: false); await SendRstStreamAsync(1); await SendRstStreamAsync(1); - tcs.TrySetResult(); await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + tcs.TrySetResult(); // Don't let the response start until after the connection stops + AssertConnectionNoError(); } From 76dd35e9b727fe1dad741e160426b67a976d24f6 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Mon, 9 Mar 2026 22:16:16 -0500 Subject: [PATCH 2/2] Fix RST_STREAM additional reset test ordering Wait for the request to be aborted before releasing the application delegate gate in RST_STREAM_IncompleteRequest_AdditionalResetFrame_IgnoreAdditionalReset. This preserves the test intent while avoiding both the HEADERS-vs-GOAWAY race and the shutdown timeout.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Http2/Http2ConnectionTests.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs index 874cbcd26dec..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,16 +3597,22 @@ 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); - await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + await abortedTcs.Task; + + tcs.TrySetResult(); // Don't let the response start until after the request aborts - tcs.TrySetResult(); // Don't let the response start until after the connection stops + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); AssertConnectionNoError(); }