Skip to content

Allow opening multiple HTTP/2 connections at a time#129486

Draft
MihaZupan wants to merge 1 commit into
dotnet:mainfrom
MihaZupan:http-parallelH2connect
Draft

Allow opening multiple HTTP/2 connections at a time#129486
MihaZupan wants to merge 1 commit into
dotnet:mainfrom
MihaZupan:http-parallelH2connect

Conversation

@MihaZupan

Copy link
Copy Markdown
Member

Testing a possible implementation of #66944

@MihaZupan MihaZupan added this to the 11.0.0 milestone Jun 16, 2026
@MihaZupan MihaZupan self-assigned this Jun 16, 2026
Copilot AI review requested due to automatic review settings June 16, 2026 23:10
@MihaZupan

Copy link
Copy Markdown
Member Author

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 SocketsHttpHandler’s HTTP/2 connection injection logic to allow multiple HTTP/2 connection attempts to be started in parallel under load (when multiple connections are enabled), and adds functional tests to validate the new behavior.

Changes:

  • Update HTTP/2 pool injection heuristics to compute and start multiple concurrent connection attempts based on queued request count and observed SETTINGS_MAX_CONCURRENT_STREAMS.
  • Adjust HTTP/2 per-connection initial stream concurrency estimation until the peer’s SETTINGS frame is observed.
  • Add/extend functional tests covering parallel connection attempts and the disabled-multiple-connections scenario.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs Adds new HTTP/2 functional tests for parallel connection-attempt injection and for the disabled-multiple-connections case; tweaks server backlog for a low-concurrency memoization test.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs Initializes _maxConcurrentStreams based on the pool’s last-seen value, falling back to InitialMaxConcurrentStreams until SETTINGS are received.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.Http2.cs Reworks HTTP/2 connection injection to support starting multiple connection attempts in parallel and tracks a count of pending HTTP/2 connections.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.Http1.cs Renames the max-connection limit field usage to a shared _maxHttpConnections identifier.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.cs Changes _lastSeenHttp2MaxConcurrentStreams initialization (now starts as “unknown”).

connectionsToInject = (int)((_http2RequestQueue.Count + concurrency - 1) / concurrency);

// This step may be delayed until something else happened (e.g. a previous connection attempt completed / another request is queued),
// so there can be a slight delay until we start agressively opening many connections in case of an initial burst of requests on a new connection pool.
Comment on lines 55 to +56
// Same as the above, but for SETTINGS_MAX_CONCURRENT_STREAMS.
internal uint _lastSeenHttp2MaxConcurrentStreams = Http2Connection.InitialMaxConcurrentStreams;
internal uint _lastSeenHttp2MaxConcurrentStreams;
return await DefaultConnectCallback(context.DnsEndPoint, ct).ConfigureAwait(false);
};

HttpClient client = CreateHttpClient(handler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants