Skip to content

Commit

Permalink
fix: make pipelining limit work for h2 (#2875)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag authored Feb 28, 2024
1 parent 00f1914 commit a55d61f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/dispatcher/client-h1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -735,6 +735,7 @@ async function connectH1 (client, socket) {

return {
version: 'h1',
defaultPipelining: 1,
write (...args) {
return writeH1(client, ...args)
},
Expand Down
1 change: 1 addition & 0 deletions lib/dispatcher/client-h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ async function connectH2 (client, socket) {

return {
version: 'h2',
defaultPipelining: Infinity,
write (...args) {
// TODO (fix): return
writeH2(client, ...args)
Expand Down
12 changes: 7 additions & 5 deletions lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const connectH2 = require('./client-h2.js')

const kClosedResolve = Symbol('kClosedResolve')

function getPipelining (client) {
return client[kPipelining] ?? client[kHTTPContext]?.defaultPipelining ?? 1
}

/**
* @type {import('../../types/client.js').default}
*/
Expand Down Expand Up @@ -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
)
}
Expand Down Expand Up @@ -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]]
Expand Down

0 comments on commit a55d61f

Please sign in to comment.