Skip to content

fix(h2): keep the connection ref'd while requests are outstanding - #5605

Merged
mcollina merged 1 commit into
v7.xfrom
fix/h2-session-close-liveness-v7
Jul 29, 2026
Merged

fix(h2): keep the connection ref'd while requests are outstanding#5605
mcollina merged 1 commit into
v7.xfrom
fix/h2-session-close-liveness-v7

Conversation

@mcollina

Copy link
Copy Markdown
Member

resumeH2() unreffed the socket and the session whenever the peer advertised SETTINGS_MAX_CONCURRENT_STREAMS = 0, regardless of whether anything was still queued:

if (client[kSize] === 0 || client[kMaxConcurrentStreams] === 0) {
  socket.unref()
  client[kHTTP2Session].unref()
}

A peer may legitimately advertise 0 to refuse new streams for a while (RFC 9113 §6.5.2) — graceful drain, overload shedding, a load balancer draining a backend. A request queued behind that owns no handle and arms no timer of its own, so once the connection was unreffed there was nothing left holding the event loop open.

The result is a process that exits with status 0 while an awaited request never settles:

warm-up request OK; server now advertises maxConcurrentStreams: 0
issuing the second request … (this await never returns)
>>> process exiting with code 0 — reached line: warm-up done

No error, no warning, no non-zero exit code — the code after the await simply never runs. For a job or a CLI that means silently skipped work reported as success.

Unref only when there is genuinely nothing outstanding.

Test

test/http2-max-concurrent-streams-zero-unref.js drives a child process whose only live work is the queued request, against a server that drains to maxConcurrentStreams: 0. Staying alive is the pass condition; exiting 0 is the bug. Verified to fail before this change (the process exited cleanly with a request still outstanding) and pass after.

test/+(http2|h2)*.js: 51 pass. Full unit suite: 1304 pass, 0 fail.

Note

This makes the failure visible rather than silent — the request itself is still stuck until a stream timeout fires. #5604 (fix(h2): honour headersTimeout) is what bounds that wait properly; the two are independent but complementary.

🤖 Generated with Claude Code

https://claude.ai/code/session_01A49JamgF2TkZHu5h58ChUM

resumeH2() unreffed the socket and the session whenever the peer advertised
SETTINGS_MAX_CONCURRENT_STREAMS = 0, regardless of whether anything was
still queued:

    if (client[kSize] === 0 || client[kMaxConcurrentStreams] === 0) {

A peer may legitimately advertise 0 to refuse new streams for a while
(RFC 9113 6.5.2). A request queued behind that owns no handle and arms no
timer of its own, so once the connection was unreffed nothing held the
event loop open: the process exited with status 0 while an awaited request
never settled, and the code after the await never ran.

Unref only when there is genuinely nothing outstanding.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A49JamgF2TkZHu5h58ChUM
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.15%. Comparing base (8d347dd) to head (c56333a).

Additional details and impacted files
@@            Coverage Diff             @@
##             v7.x    #5605      +/-   ##
==========================================
- Coverage   93.17%   93.15%   -0.02%     
==========================================
  Files         112      112              
  Lines       36751    36755       +4     
==========================================
- Hits        34241    34240       -1     
- Misses       2510     2515       +5     

☔ 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.

@mcollina
mcollina merged commit 3bf33e2 into v7.x Jul 29, 2026
37 checks passed
@mcollina
mcollina deleted the fix/h2-session-close-liveness-v7 branch July 29, 2026 07:19
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