Skip to content

Add an experimental option to avoid partitioning the connection pool by SNI - #131153

Merged
MihaZupan merged 1 commit into
dotnet:mainfrom
MihaZupan:http-sniPartition2
Jul 23, 2026
Merged

MihaZupan merged 1 commit into
dotnet:mainfrom
MihaZupan:http-sniPartition2

Conversation

@MihaZupan

Copy link
Copy Markdown
Member

Replaces #128653

This adds a way to opt-in requests into sharing connections regardless of SNI, potentially sharing connections with TLS established to a different host.
In practice it'd be used when you know you're talking with shared infrastructure that uses different hosts, and you know you can share connections to the same IP.

It's not exposed as public API for now, we can think about that for .NET 12 if it proves valuable enough.

[UnsafeAccessor(UnsafeAccessorKind.Method)]
private static extern void ExperimentalDangerousDoNotPartitionConnectionPoolBySni(HttpRequestMessage request);

@MihaZupan MihaZupan added this to the 11.0.0 milestone Jul 21, 2026
@MihaZupan
MihaZupan requested a review from a team July 21, 2026 14:19
@MihaZupan MihaZupan self-assigned this Jul 21, 2026
Copilot AI review requested due to automatic review settings July 21, 2026 14:19
@dotnet-policy-service dotnet-policy-service Bot added the linkable-framework Issues associated with delivering a linker friendly framework label Jul 21, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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 adds an experimental, non-public opt-in that allows SocketsHttpHandler to avoid partitioning the connection pool by SNI / SslHostName, enabling connection reuse across requests that vary Host while targeting the same URI host/port (e.g., shared infrastructure behind a single IP). It does so by adding an internal flag on HttpRequestMessage, honoring it in HttpConnectionPoolManager when creating the pool key, and adding functional tests across HTTP/1.1, HTTP/2, and HTTP/3.

Changes:

  • Add an internal HttpRequestMessage flag + internal method (intended to be invoked via UnsafeAccessor) to disable pool partitioning by SNI for a request.
  • Update HttpConnectionPoolManager.SendAsyncCore to use a pool key that omits SslHostName when the request opts in.
  • Add new functional tests validating pooling behavior across differing Host headers and ensure the opt-in doesn’t mix with non-opted-in requests; preserve the experimental method from trimming via ILLink descriptors.

Reviewed changes

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

File Description
src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs Adds functional tests covering connection reuse behavior across Host/SNI variations for HTTP/1.1, 2, and 3.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPoolManager.cs Alters pool key computation to optionally ignore SslHostName (SNI) for opted-in requests.
src/libraries/System.Net.Http/src/System/Net/Http/HttpRequestMessage.cs Introduces an internal flag + internal opt-in method used to disable SNI-based partitioning per request.
src/libraries/System.Net.Http/src/ILLink/ILLink.Descriptors.LibraryBuild.xml Preserves the experimental opt-in method for trimmed builds since it’s invoked via UnsafeAccessor.

@ManickaP ManickaP left a comment

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.

:shipit:

@MihaZupan
MihaZupan merged commit 35ecc51 into dotnet:main Jul 23, 2026
101 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot modified the milestones: 11.0.0, 11.0-rc1 Jul 24, 2026
hez2010 pushed a commit to hez2010/runtime that referenced this pull request Jul 26, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Net.Http linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants