Skip to content

Don't wait for control stream before processing requests#65399

Merged
BrennanConroy merged 2 commits intomainfrom
brecon/controlstream
Mar 11, 2026
Merged

Don't wait for control stream before processing requests#65399
BrennanConroy merged 2 commits intomainfrom
brecon/controlstream

Conversation

@BrennanConroy
Copy link
Copy Markdown
Member

HTTP/3 RFC implies requests can be processed before the SETTINGS frame is processed.
https://datatracker.ietf.org/doc/html/rfc9114#section-7.2.4.2

HttpClient is also already sending SETTINGS in a background task while starting the rest of it's processing: https://source.dot.net/#System.Net.Http/System/Net/Http/SocketsHttpHandler/[Http3Connection.cs](https://source.dot.net/#System.Net.Http/System/Net/Http/SocketsHttpHandler/Http3Connection.cs,103),103

This PR updates Kestrel to start the control stream and SETTINGS sending in a background thread and start processing incoming requests immediately.

Copilot AI review requested due to automatic review settings February 11, 2026 22:44
@BrennanConroy BrennanConroy added feature-kestrel area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions labels Feb 11, 2026
Copy link
Copy Markdown
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 updates Kestrel's HTTP/3 implementation to start processing incoming requests immediately without waiting for the outbound control stream to be created and SETTINGS to be sent. This change aligns with RFC 9114 section 7.2.4.2, which implies that requests can be processed before the SETTINGS frame is received, and matches HttpClient's existing behavior.

Changes:

  • Move outbound control stream creation to a background task that runs concurrently with request processing
  • Add comprehensive test coverage for scenarios where the control stream is blocked or never accepted by the client
  • Add error handling for control stream failures during cleanup to prevent hangs during graceful shutdown

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Servers/Kestrel/Core/src/Internal/Http3/Http3Connection.cs Changed control stream initialization to run asynchronously in background without blocking request processing; moved error handling to cleanup phase
src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3ConnectionTests.cs Added three unit tests covering blocked control stream scenarios: request processing, graceful shutdown, and abort
src/Servers/Kestrel/test/Interop.FunctionalTests/Http3/Http3RequestTests.cs Added two functional tests using real QUIC connections to verify graceful shutdown works when client never accepts server's control stream
src/Servers/Kestrel/test/Interop.FunctionalTests/Interop.FunctionalTests.csproj Added reference to VariableLengthIntegerHelper for HTTP/3 frame encoding in tests

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 19, 2026
return new Http3ControlStream<TContext>(application, httpConnectionContext, 0L);
OutboundControlStream = new Http3ControlStream<TContext>(application, httpConnectionContext, 0L);

// Don't delay on waiting to send outbound control stream settings.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

irrelevant comment? Was it "dont delay" because it was not an awaited task?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, should probably remove this and add a comment where we call CreateNewUnidirectionalStreamAsync

@BrennanConroy
Copy link
Copy Markdown
Member Author

/azp run

@dotnet-policy-service dotnet-policy-service Bot removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Mar 9, 2026
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@BrennanConroy BrennanConroy merged commit 1fd3d6a into main Mar 11, 2026
25 checks passed
@BrennanConroy BrennanConroy deleted the brecon/controlstream branch March 11, 2026 22:37
@dotnet-policy-service dotnet-policy-service Bot added this to the 11.0-preview3 milestone Mar 11, 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 feature-kestrel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants