Skip to content

Fix HTTP/2 Pings not being sent/enforced in multiple scenarios - #131582

Open
MihaZupan wants to merge 1 commit into
dotnet:mainfrom
MihaZupan:http-h2pingsFixes
Open

Fix HTTP/2 Pings not being sent/enforced in multiple scenarios#131582
MihaZupan wants to merge 1 commit into
dotnet:mainfrom
MihaZupan:http-h2pingsFixes

Conversation

@MihaZupan

Copy link
Copy Markdown
Member

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

  1. The connection reached its stream limit and was temporarily removed from the available list.
  2. We received a GOAWAY frame indicating that existing requests will be processed. The first thing we do when receiving the frame is to mark the connection as shut down, and remove it from the available pool.
  3. If the SocketsHttpHandler instance 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.

@MihaZupan MihaZupan added this to the 11.0.0 milestone Jul 30, 2026
@MihaZupan
MihaZupan requested a review from a team July 30, 2026 11:57
@MihaZupan MihaZupan self-assigned this Jul 30, 2026
Copilot AI review requested due to automatic review settings July 30, 2026 11:57
@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 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.

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.

SocketsHttpHandler HTTP/2 pings are broken in multiple scenarios

2 participants