Skip to content

Atomically send GOAWAY during HTTP/2 abort#65465

Open
adityamandaleeka wants to merge 1 commit intodotnet:mainfrom
adityamandaleeka:fix-abort-h2race
Open

Atomically send GOAWAY during HTTP/2 abort#65465
adityamandaleeka wants to merge 1 commit intodotnet:mainfrom
adityamandaleeka:fix-abort-h2race

Conversation

@adityamandaleeka
Copy link
Member

Fix a race in Http2Connection.Abort where ProcessRequestsAsync cleanup could call _frameWriter.Complete() between WriteGoAwayAsync and Abort(), causing GOAWAY to be dropped.

Add Http2FrameWriter.AbortWithGoAway() and use it from Http2Connection.Abort() to perform GOAWAY write/flush and abort under one lock acquisition.

I'm intentionally not adding a regression test for this because the amount of timing nonsense you have to do to simulate it defeats the purpose of the test. I noticed this happening in CI though so hopefully we'll see less flakiness here.

Copilot AI review requested due to automatic review settings February 18, 2026 20:18
@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 race condition in HTTP/2 connection abort handling where a GOAWAY frame could be lost. The race occurred when ProcessRequestsAsync cleanup called _frameWriter.Complete() between the WriteGoAwayAsync and Abort() calls, causing the _completed flag to be set to true and the GOAWAY frame to be discarded.

Changes:

  • Introduced Http2FrameWriter.AbortWithGoAway() method to atomically write GOAWAY frame and abort connection under a single lock acquisition
  • Modified Http2Connection.Abort() to use the new atomic method when closing the connection for the first time
  • Added detailed documentation explaining the race condition and the fix

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/Http2FrameWriter.cs Added new AbortWithGoAway() method that atomically writes GOAWAY frame and performs connection abort under single lock to prevent race condition
src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs Updated Abort() method to use new atomic AbortWithGoAway() when TryClose() succeeds, and regular Abort() otherwise

@adityamandaleeka
Copy link
Member Author

ha, this ran into the flakniess fixed in #65456

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.

1 participant

Comments