From c0df7b2dbf6c9a9ec9cd52c2cf75433baf68ed0d Mon Sep 17 00:00:00 2001 From: rambo Date: Fri, 16 Jan 2026 12:40:11 +0800 Subject: [PATCH] fix(pool): add useH2c option support for multiple connections The Pool class was not passing the useH2c option to buildConnector and kOptions, causing HTTPParserError when using Agent with useH2c and connections > 1. This fix ensures that: - useH2c is extracted from constructor parameters - useH2c is passed to buildConnector for proper connection setup - useH2c is included in kOptions for client instances Fixes issue with h2c (HTTP/2 Cleartext) failing on second connection when Pool creates multiple Client instances. Before: connections > 1 with useH2c caused HTTP/1.1 parser to receive HTTP/2 binary frames, resulting in protocol mismatch error After: All connections properly use HTTP/2 cleartext protocol Fixes #4737 --- lib/dispatcher/pool.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/dispatcher/pool.js b/lib/dispatcher/pool.js index 77fd5326696..35f335ff857 100644 --- a/lib/dispatcher/pool.js +++ b/lib/dispatcher/pool.js @@ -36,6 +36,7 @@ class Pool extends PoolBase { autoSelectFamily, autoSelectFamilyAttemptTimeout, allowH2, + useH2c, clientTtl, ...options } = {}) { @@ -56,6 +57,7 @@ class Pool extends PoolBase { ...tls, maxCachedSessions, allowH2, + useH2c, socketPath, timeout: connectTimeout, ...(typeof autoSelectFamily === 'boolean' ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined), @@ -67,7 +69,7 @@ class Pool extends PoolBase { this[kConnections] = connections || null this[kUrl] = util.parseOrigin(origin) - this[kOptions] = { ...util.deepClone(options), connect, allowH2, clientTtl } + this[kOptions] = { ...util.deepClone(options), connect, allowH2, useH2c, clientTtl } this[kOptions].interceptors = options.interceptors ? { ...options.interceptors } : undefined