fix(pool): propagate useH2c to connector when connections > 1#5031
Open
SAY-5 wants to merge 1 commit intonodejs:mainfrom
Open
fix(pool): propagate useH2c to connector when connections > 1#5031SAY-5 wants to merge 1 commit intonodejs:mainfrom
SAY-5 wants to merge 1 commit intonodejs:mainfrom
Conversation
When constructing a Pool, the useH2c option was not destructured from the constructor options. As a result, when Pool built its own connector via buildConnector, useH2c was lost and the resulting socket never had its alpnProtocol set to 'h2'. Child Clients then received an h2c connector that produced h1 sockets, causing HTTPParserError on the first response that contained an HTTP/2 SETTINGS frame. This only affected Agent/Pool with connections > 1 because connections === 1 short-circuits to a Client, which already destructures and forwards useH2c. Fixes nodejs#4737
metcoder95
approved these changes
Apr 15, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5031 +/- ##
=======================================
Coverage 93.02% 93.03%
=======================================
Files 110 110
Lines 35793 35795 +2
=======================================
+ Hits 33298 33303 +5
+ Misses 2495 2492 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 #4737.
When constructing a
Pooldirectly (or indirectly viaAgentwithconnections > 1), theuseH2coption was not in the constructor's destructured parameter list. It ended up in...optionsand was therefore not forwarded tobuildConnector. The resulting connector did not setsocket.alpnProtocol = 'h2'for plaintext h2c, so child Clients picked the HTTP/1 context for the new socket. The first response carrying an HTTP/2SETTINGSframe then failed parsing with:connections === 1was unaffected becauseAgent's default factory short-circuits tonew Client(origin, opts), andClientalready destructures and forwardsuseH2ctobuildConnector.The fix adds
useH2ctoPool's destructured options, passes it tobuildConnector, and stores it onkOptionsfor symmetry withallowH2.I added two regression tests in
test/h2c-client.jscovering bothPoolandAgentwithuseH2c: true, connections: 2against anhttp2.createServer()(h2c) backend. Both tests fail onmainwith the parser error and pass with the fix.Test results:
test/h2c-client.js: 10/10 pass (8 existing + 2 new)test/pool.js: 35/35 passtest/http2-dispatcher.js: 11/11 passtest/http2-agent.js,test/http2-alpn.js: passeslint lib/dispatcher/pool.js test/h2c-client.js: cleanManually verified the original repro from the issue (Promise.all of 3 requests through
new Agent({ useH2c: true, connections: 2 })) now succeeds.