Skip to content

fix(pool): release saturated h2 protocol probes after SETTINGS - #6170

Merged
mcollina merged 5 commits into
nodejs:mainfrom
EpicHigh:fix/h2-pool-saturation
Nov 6, 2026
Merged

mcollina merged 5 commits into
nodejs:mainfrom
EpicHigh:fix/h2-pool-saturation

Conversation

@EpicHigh

@EpicHigh EpicHigh commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

This relates to...

When an HTTP/2 peer advertises SETTINGS_MAX_CONCURRENT_STREAMS = 1, a fresh Pool can leave its second request queued for as long as the first response stays open, even though another connection is allowed. This happens both during negotiation and after the first response headers arrive.

Related to the protocol gate introduced in #5799. This is distinct from #6142: the probe connects successfully here, and its first request remains active rather than failing request validation.

Rationale

The h2 probe currently waits for its Client to emit drain. A long-lived stream can consume the peer's entire stream allowance, preventing that event. Meanwhile the outstanding probe prevents the Pool from selecting a new connection.

Changes

  • Release the current protocol probe after peer SETTINGS arrive, or immediately if they have already arrived.
  • Reconsider queued requests through the existing Pool dispatcher selection, retaining the connection limit and ALPN negotiation gate.
  • Keep backpressure when the Pool queue is empty and the connection limit prevents another dispatcher. Avoid invoking a custom factory for unused capacity, and avoid creating spare dispatchers after close or destroy.
  • Handle queued dispatcher-selection failures before transferring request ownership; keep queue-drain capacity checks from invoking a factory after a request has been accepted.
  • Add sixteen regressions covering TLS h2 and h2c, requests queued during and after negotiation, and backpressure with one or two allowed connections. They verify that a queued POST arrives once and that a saturated single-connection Pool does not emit drain prematurely. Factory failures during queue draining reject only the affected request and preserve its async context without replaying accepted work. A synchronous retry from an error callback retains backpressure until capacity is available.

No public API changes.

Status

Without the probe-release fix, the four saturation cases time out after 5 seconds on Node 24.22.1. On the initial PR head, both single-connection backpressure cases fail because drain fires while the only stream is still occupied. With the current fix:

  • Node 24.22.1: npm run test:h2 — 163 core and 14 fetch tests passed.

  • Node 24.22.1: full unit suite — 1,678 passed, 3 skipped, 0 failed; BalancedPool — 25 passed.

  • Bun 1.4.4: all sixteen regressions passed.

  • npm run lint and git diff --check passed.

  • Existing cold-burst multiplexing, h1 fallback and single-connection tests pass.

  • I have read and agreed to the Developer's Certificate of Origin

  • Tested

  • Benchmarked (optional; not run)

  • Documented (no API/documentation change)

  • Review ready

  • In review

  • Merge ready

@codecov-commenter

codecov-commenter commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.67%. Comparing base (76f0b3e) to head (1d24348).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6170   +/-   ##
=======================================
  Coverage   91.67%   91.67%           
=======================================
  Files         113      113           
  Lines       44419    44443   +24     
=======================================
+ Hits        40721    40744   +23     
- Misses       3698     3699    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@EpicHigh
EpicHigh marked this pull request as ready for review November 6, 2026 03:37

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

lgtm

@mcollina
mcollina merged commit 55bf294 into nodejs:main Nov 6, 2026
38 checks passed
@EpicHigh
EpicHigh deleted the fix/h2-pool-saturation branch November 6, 2026 11:10
@github-actions github-actions Bot mentioned this pull request Nov 7, 2026
@github-actions github-actions Bot mentioned this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants