From b94cb494d0989f462f3e8f6dc885a8ab53b4dd43 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 28 Feb 2024 12:22:14 +0100 Subject: [PATCH] fix: make pipelining limit work for h2 --- lib/dispatcher/client-h1.js | 2 +- lib/dispatcher/client.js | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/dispatcher/client-h1.js b/lib/dispatcher/client-h1.js index df644e0360c..66b9cf98f36 100644 --- a/lib/dispatcher/client-h1.js +++ b/lib/dispatcher/client-h1.js @@ -612,7 +612,7 @@ class Parser { // have been queued since then. util.destroy(socket, new InformationalError('reset')) return constants.ERROR.PAUSED - } else if (client[kPipelining] === 1) { + } else if (client[kPipelining] == null || client[kPipelining] === 1) { // We must wait a full event loop cycle to reuse this socket to make sure // that non-spec compliant servers are not closing the connection even if they // said they won't. diff --git a/lib/dispatcher/client.js b/lib/dispatcher/client.js index 29dde5cdab3..7ca2d58e3ae 100644 --- a/lib/dispatcher/client.js +++ b/lib/dispatcher/client.js @@ -66,6 +66,10 @@ const connectH2 = require('./client-h2.js') const kClosedResolve = Symbol('kClosedResolve') +function getPipelining (client) { + return client[kPipelining] ?? (client[kHTTPContext]?.version === 'h2' ? Infinity : 1) +} + /** * @type {import('../../types/client.js').default} */ @@ -280,7 +284,7 @@ class Client extends DispatcherBase { const socket = this[kSocket] return ( (socket && (socket[kReset] || socket[kWriting] || socket[kBlocking])) || - (this[kSize] >= (this[kPipelining] || 1)) || + (this[kSize] >= (getPipelining(this) || 1)) || this[kPending] > 0 ) } @@ -564,10 +568,8 @@ function _resume (client, sync) { return } - if (client[kHTTPContext]?.version === 'h1') { - if (client[kRunning] >= (client[kPipelining] || 1)) { - return - } + if (client[kRunning] >= (getPipelining(client) || 1)) { + return } const request = client[kQueue][client[kPendingIdx]]