Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pipelining logic is not relevant for h2 #2850

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 40 additions & 41 deletions lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,21 +457,10 @@ function onHTTP2GoAway (code) {
client[kSocket] = null
client[kHTTP2Session] = null

if (client.destroyed) {
assert(this[kPending] === 0)

// Fail entire queue.
const requests = client[kQueue].splice(client[kRunningIdx])
for (let i = 0; i < requests.length; i++) {
const request = requests[i]
errorRequest(this, request, err)
}
} else if (client[kRunning] > 0) {
// Fail head of pipeline.
const request = client[kQueue][client[kRunningIdx]]
client[kQueue][client[kRunningIdx]++] = null

errorRequest(client, request, err)
const requests = client[kQueue].splice(client[kRunningIdx])
for (let i = 0; i < requests.length; i++) {
const request = requests[i]
errorRequest(this, request, err)
}

client[kPendingIdx] = client[kRunningIdx]
Expand Down Expand Up @@ -1089,7 +1078,9 @@ function onSocketClose () {

client[kSocket] = null

if (client.destroyed) {
// TODO (fix): Always fail entire queue

if (client.destroyed || client[kHTTPConnVersion] === 'h2') {
assert(client[kPending] === 0)

// Fail entire queue.
Expand Down Expand Up @@ -1325,8 +1316,10 @@ function _resume (client, sync) {
return
}

if (client[kRunning] >= (client[kPipelining] || 1)) {
return
if (client[kHTTPConnVersion] === 'h1') {
if (client[kRunning] >= (client[kPipelining] || 1)) {
return
}
}

const request = client[kQueue][client[kPendingIdx]]
Expand All @@ -1353,35 +1346,41 @@ function _resume (client, sync) {
return
}

if (socket.destroyed || socket[kWriting] || socket[kReset] || socket[kBlocking]) {
if (socket.destroyed) {
return
}

if (client[kRunning] > 0 && !request.idempotent) {
// Non-idempotent request cannot be retried.
// Ensure that no other requests are inflight and
// could cause failure.
return
}
if (client[kHTTPConnVersion] === 'h1') {
if (socket[kWriting] || socket[kReset] || socket[kBlocking]) {
return
}

if (client[kRunning] > 0 && (request.upgrade || request.method === 'CONNECT')) {
// Don't dispatch an upgrade until all preceding requests have completed.
// A misbehaving server might upgrade the connection before all pipelined
// request has completed.
return
}
if (client[kRunning] > 0 && !request.idempotent) {
// Non-idempotent request cannot be retried.
// Ensure that no other requests are inflight and
// could cause failure.
return
}

if (client[kRunning] > 0 && util.bodyLength(request.body) !== 0 &&
(util.isStream(request.body) || util.isAsyncIterable(request.body) || util.isFormDataLike(request.body))) {
// Request with stream or iterator body can error while other requests
// are inflight and indirectly error those as well.
// Ensure this doesn't happen by waiting for inflight
// to complete before dispatching.
if (client[kRunning] > 0 && (request.upgrade || request.method === 'CONNECT')) {
// Don't dispatch an upgrade until all preceding requests have completed.
// A misbehaving server might upgrade the connection before all pipelined
// request has completed.
return
}

// Request with stream or iterator body cannot be retried.
// Ensure that no other requests are inflight and
// could cause failure.
return
if (client[kRunning] > 0 && util.bodyLength(request.body) !== 0 &&
(util.isStream(request.body) || util.isAsyncIterable(request.body) || util.isFormDataLike(request.body))) {
// Request with stream or iterator body can error while other requests
// are inflight and indirectly error those as well.
// Ensure this doesn't happen by waiting for inflight
// to complete before dispatching.

// Request with stream or iterator body cannot be retried.
// Ensure that no other requests are inflight and
// could cause failure.
return
}
}

if (!request.aborted && write(client, request)) {
Expand Down
Loading