Skip to content

Add configurable HTTP connection eviction, expose ConnectionId APIs#130476

Open
MihaZupan wants to merge 7 commits into
dotnet:mainfrom
MihaZupan:http-connectionEviction
Open

Add configurable HTTP connection eviction, expose ConnectionId APIs#130476
MihaZupan wants to merge 7 commits into
dotnet:mainfrom
MihaZupan:http-connectionEviction

Conversation

@MihaZupan

@MihaZupan MihaZupan commented Jul 10, 2026

Copy link
Copy Markdown
Member

Closes #130102
Closes #130108

Implements the new APIs from the two issues above (NO-MERGE while those are still going through API review).
More details around the intended behavior are in those issues.

@MihaZupan MihaZupan added this to the 11.0.0 milestone Jul 10, 2026
@MihaZupan MihaZupan self-assigned this Jul 10, 2026
Copilot AI review requested due to automatic review settings July 10, 2026 11:10
@MihaZupan MihaZupan added NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) NO-REVIEW Experimental/testing PR, do NOT review it labels Jul 10, 2026
@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 new experimental connection-level diagnostics and control points to System.Net.Http’s SocketsHttpHandler, including a configurable pooled-connection eviction callback and a connection identifier that’s propagated through connection establishment, request sending, and plaintext stream filtering. It also adds functional coverage across HTTP/1.1, HTTP/2, and HTTP/3 (including Alt-Svc).

Changes:

  • Introduces experimental public APIs: SocketsHttpHandler.ShouldEvictConnection, SocketsHttpConnectionEvictionContext, and HttpRequestMessage.ConnectionId (plus ConnectionId surfacing in connect/plaintext-filter contexts).
  • Implements eviction evaluation in the connection pool and stamps ConnectionId onto requests for HTTP/1.1, HTTP/2, and HTTP/3.
  • Adds functional tests (mostly OuterLoop) exercising eviction behavior and connection id propagation, plus warning suppressions for the experimental diagnostic ID.

Reviewed changes

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

Show a summary per file
File Description
src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj Links Experimentals.cs into unit tests to support experimental attribute usage/constants.
src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj Suppresses SYSLIB5008 for functional tests consuming experimental APIs.
src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs Adds extensive functional coverage for eviction callback behavior and ConnectionId stamping across protocols and scenarios.
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AltSvc.cs Adds HTTP/3 Alt-Svc tests validating eviction context endpoint reporting.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpPlaintextStreamFilterContext.cs Adds ConnectionId to plaintext stream filter context (experimental).
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs Adds ShouldEvictConnection experimental callback API.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpConnectionEvictionContext.cs New public experimental context type for eviction decisions.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpConnectionContext.cs Adds ConnectionId to connect callback context (experimental).
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionSettings.cs Plumbs eviction callback through handler settings cloning/normalization.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPoolManager.cs Adjusts pool maintenance timer cadence when eviction callback is configured.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionBase.cs Adds eviction state/context and evaluation plumbing at the connection level.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs Stamps HttpRequestMessage.ConnectionId on HTTP/1.1 requests.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3Connection.cs Ensures HTTP/3 requests get ConnectionId and eviction context reports the connected endpoint.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs Stamps HttpRequestMessage.ConnectionId on HTTP/2 requests.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.Http3.cs Passes connected endpoint into HTTP/3 connection establishment for eviction context accuracy.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.Http2.cs Threads connection id through HTTP/2 connection construction/filtering paths.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.Http1.cs Threads connection id through HTTP/1.1 connection construction/filtering and triggers eviction evaluation on return.
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.cs Adds eviction evaluation pass scheduling and clears ConnectionId across retry attempts; allocates connection id before connect for correlation.
src/libraries/System.Net.Http/src/System/Net/Http/HttpRequestMessage.cs Adds experimental ConnectionId property to requests.
src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/SocketsHttpHandler.cs Adds ShouldEvictConnection stub throwing PNSE for browser handler.
src/libraries/System.Net.Http/src/System.Net.Http.csproj Suppresses SYSLIB5008 for internal use and includes new source file + Experimentals.cs.
src/libraries/System.Net.Http/ref/System.Net.Http.cs Adds the new public API surface to the ref assembly contract.
src/libraries/Common/src/System/Experimentals.cs Defines the experimental diagnostic ID constant for the new APIs.
docs/project/list-of-diagnostics.md Registers the new experimental diagnostic ID in the central list.

Comment thread src/libraries/System.Net.Http/ref/System.Net.Http.cs
Comment thread docs/project/list-of-diagnostics.md
@MihaZupan

Copy link
Copy Markdown
Member Author

PTAL @dotnet/ncl. I'll improve the tests, but the product side of the change should be ready for review

@rzikm rzikm 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.

Impl. LGTM, didn't look at tests too much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Net.Http NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Enable easier correlation of HTTP requests to the ConnectionId [API Proposal]: Configurable HTTP connection eviction

3 participants