Skip to content

Fix flaky Http2 test by using consistent ConnectionEndReason for closed streams#65456

Merged
adityamandaleeka merged 3 commits intodotnet:mainfrom
adityamandaleeka:connectionendreason_metrics
Feb 19, 2026
Merged

Fix flaky Http2 test by using consistent ConnectionEndReason for closed streams#65456
adityamandaleeka merged 3 commits intodotnet:mainfrom
adityamandaleeka:connectionendreason_metrics

Conversation

@adityamandaleeka
Copy link
Member

Summary

ProcessDataFrameAsync's "stream not found" path used ConnectionEndReason.UnknownStream, but the stream was known-and-closed (ThrowIfIncomingFrameSentToIdleStream already rejects truly unknown streams). This was inconsistent with the RstStreamReceived and EndStreamReceived paths which both use FrameAfterStreamClose, causing a flaky test (AbortedStream_ResetsAndDrainsRequest_RefusesFramesAfterClientReset) depending on whether stream cleanup completed before the next frame arrived.

Changes

  • Http2Connection.cs: Changed ConnectionEndReason.UnknownStreamFrameAfterStreamClose in ProcessDataFrameAsync's "stream not found" path, making it consistent with the other closed-stream code paths.
  • Http2ConnectionTests.cs: Updated the test assertion to expect FrameAfterStreamClose deterministically.

Impact

Metrics-only change. Same exception type, HTTP/2 error code (STREAM_CLOSED), error message, and GOAWAY behavior. Only the ConnectionEndReason metric tag on kestrel.connection.duration changes.

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.
Copilot AI review requested due to automatic review settings February 18, 2026 04:04
@github-actions github-actions bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Feb 18, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ProcessDataFrameAsync to use FrameAfterStreamClose instead of UnknownStream when 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 FrameAfterStreamClose deterministically 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

@adityamandaleeka
Copy link
Member Author

Flaky test. Hopefully this fixes it: #65465

@adityamandaleeka adityamandaleeka merged commit 97c3db9 into dotnet:main Feb 19, 2026
25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 11.0-preview2 milestone Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments