Add configurable HTTP connection eviction, expose ConnectionId APIs#130476
Add configurable HTTP connection eviction, expose ConnectionId APIs#130476MihaZupan wants to merge 7 commits into
Conversation
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
There was a problem hiding this comment.
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, andHttpRequestMessage.ConnectionId(plusConnectionIdsurfacing in connect/plaintext-filter contexts). - Implements eviction evaluation in the connection pool and stamps
ConnectionIdonto 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. |
|
PTAL @dotnet/ncl. I'll improve the tests, but the product side of the change should be ready for review |
rzikm
left a comment
There was a problem hiding this comment.
Impl. LGTM, didn't look at tests too much
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.