Skip to content

Commit

Permalink
fix: make pipelining limit work for h2
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Feb 28, 2024
1 parent 861f782 commit c2360bd
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ const connectH2 = require('./client-h2.js')

const kClosedResolve = Symbol('kClosedResolve')

function getPipelining (client) {
return client[kPipelining] ??
(client[kHTTPContext]?.version === 'h2' ? Infinity : null) ??
(client[kHTTPContext]?.version === 'h1' ? Infinity : null) ??
0
}

/**
* @type {import('../../types/client.js').default}
*/
Expand Down Expand Up @@ -213,7 +220,7 @@ class Client extends DispatcherBase {
this[kUrl] = util.parseOrigin(url)
this[kConnector] = connect
this[kSocket] = null
this[kPipelining] = pipelining != null ? pipelining : 1
this[kPipelining] = pipelining
this[kMaxHeadersSize] = maxHeaderSize || http.maxHeaderSize
this[kKeepAliveDefaultTimeout] = keepAliveTimeout == null ? 4e3 : keepAliveTimeout
this[kKeepAliveMaxTimeout] = keepAliveMaxTimeout == null ? 600e3 : keepAliveMaxTimeout
Expand Down Expand Up @@ -280,7 +287,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)) ||
this[kPending] > 0
)
}
Expand Down Expand Up @@ -564,10 +571,8 @@ function _resume (client, sync) {
return
}

if (client[kHTTPContext]?.version === 'h1') {
if (client[kRunning] >= (client[kPipelining] || 1)) {
return
}
if (client[kRunning] >= getPipelining(client)) {
return
}

const request = client[kQueue][client[kPendingIdx]]
Expand Down

0 comments on commit c2360bd

Please sign in to comment.