Fix flaky Http2 test by using consistent ConnectionEndReason for closed streams#65456
Merged
adityamandaleeka merged 3 commits intodotnet:mainfrom Feb 19, 2026
Merged
Conversation
Move tcs.TrySetResult() after WaitForConnectionErrorAsync to prevent the response HEADERS from racing with the GOAWAY frame. Same fix pattern as dotnet#57450 applied to AdditionalDataFrames and AdditionalTrailerFrames variants.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a flaky HTTP/2 test by making the ConnectionEndReason consistent when DATA frames are received for closed streams. The issue occurred because there was a race condition where stream cleanup timing affected which ConnectionEndReason value was used for metrics, causing test flakiness. The fix ensures that DATA frames on closed streams consistently use ConnectionEndReason.FrameAfterStreamClose regardless of cleanup timing.
Changes:
- Updated
ProcessDataFrameAsyncto useFrameAfterStreamCloseinstead ofUnknownStreamwhen DATA frames are received for closed streams - Fixed test timing issues by moving
tcs.TrySetResult()calls to occur after waiting for connection errors - Updated test assertion to expect
FrameAfterStreamClosedeterministically for DATA frames
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs | Changed ConnectionEndReason from UnknownStream to FrameAfterStreamClose for DATA frames received on closed streams, making it consistent with RstStreamReceived and EndStreamReceived paths |
| src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs | Moved tcs.TrySetResult() to after error handling completes to eliminate race conditions, and updated test assertion to expect FrameAfterStreamClose for DATA frames on closed streams |
DeagleGross
approved these changes
Feb 18, 2026
Member
Author
|
Flaky test. Hopefully this fixes it: #65465 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ProcessDataFrameAsync's "stream not found" path usedConnectionEndReason.UnknownStream, but the stream was known-and-closed (ThrowIfIncomingFrameSentToIdleStreamalready rejects truly unknown streams). This was inconsistent with theRstStreamReceivedandEndStreamReceivedpaths which both useFrameAfterStreamClose, causing a flaky test (AbortedStream_ResetsAndDrainsRequest_RefusesFramesAfterClientReset) depending on whether stream cleanup completed before the next frame arrived.Changes
Http2Connection.cs: ChangedConnectionEndReason.UnknownStream→FrameAfterStreamCloseinProcessDataFrameAsync's "stream not found" path, making it consistent with the other closed-stream code paths.Http2ConnectionTests.cs: Updated the test assertion to expectFrameAfterStreamClosedeterministically.Impact
Metrics-only change. Same exception type, HTTP/2 error code (
STREAM_CLOSED), error message, and GOAWAY behavior. Only theConnectionEndReasonmetric tag onkestrel.connection.durationchanges.