Fix HTTP/2 Pings not being sent/enforced in multiple scenarios - #131582
Open
MihaZupan wants to merge 1 commit into
Open
Fix HTTP/2 Pings not being sent/enforced in multiple scenarios#131582MihaZupan wants to merge 1 commit into
MihaZupan wants to merge 1 commit into
Conversation
|
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. |
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts SocketsHttpHandler’s HTTP/2 keep-alive ping/timeout enforcement so it continues to function even when a connection is no longer “available” in the pool (e.g., draining after GOAWAY or temporarily removed due to stream limits), and so pings can continue for in-flight requests after handler disposal.
Changes:
- Track all live HTTP/2 connections that still require heartbeats separately from the “available” connection list, and drive ping heartbeats from that tracking list.
- Keep the HTTP/2 heartbeat timer alive past handler disposal and stop it only once the manager is disposed and no heartbeat-relevant connections remain.
- Add functional tests covering GOAWAY, max concurrent streams, and handler disposal scenarios for HTTP/2 keep-alive pings.
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.Http2KeepAlivePing.cs | Adds OuterLoop functional coverage for GOAWAY/max-streams/handler-dispose keep-alive ping behavior, plus helper for awaiting pings. |
| src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPoolManager.cs | Changes heartbeat timer lifetime so pings can continue for in-flight requests after Dispose; timer self-terminates when safe. |
| src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs | Registers HTTP/2 connections for pool heartbeat across full lifetime; gates pings until setup completes; unregisters on teardown. |
| src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.Http2.cs | Introduces a heartbeat-specific HTTP/2 connection tracking list and updates pool HeartBeat() to use it. |
| src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionPool/HttpConnectionPool.cs | Prevents pool cleanup from disposing a pool that still has draining HTTP/2 connections needing heartbeats. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #120179
There were 3 scenarios where we'd stop sending pings / checking whether the PONG delay was hit, as called out in the issue
SocketsHttpHandlerinstance is disposed. Today any existing requests on the instance will continue as normal, but we're also stopping the heartbeat timer and therefore breaking pings. This case could be looked at as user error to a degree though.The issue boils down to using the same list of connections that are still available with capacity, and disposing the timer prematurely.
This fixes that by tracking all H2 connections that still need pings separately, and avoids disposing the timer until that list is also empty instead of immediately on handler disposal.