Skip to content

Commit 16e49ff

Browse files
authored
fix: pipelining logic is not relevant for h2 (#2850)
1 parent 8b131ab commit 16e49ff

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

lib/dispatcher/client.js

+40-41
Original file line numberDiff line numberDiff line change
@@ -457,21 +457,10 @@ function onHTTP2GoAway (code) {
457457
client[kSocket] = null
458458
client[kHTTP2Session] = null
459459

460-
if (client.destroyed) {
461-
assert(this[kPending] === 0)
462-
463-
// Fail entire queue.
464-
const requests = client[kQueue].splice(client[kRunningIdx])
465-
for (let i = 0; i < requests.length; i++) {
466-
const request = requests[i]
467-
errorRequest(this, request, err)
468-
}
469-
} else if (client[kRunning] > 0) {
470-
// Fail head of pipeline.
471-
const request = client[kQueue][client[kRunningIdx]]
472-
client[kQueue][client[kRunningIdx]++] = null
473-
474-
errorRequest(client, request, err)
460+
const requests = client[kQueue].splice(client[kRunningIdx])
461+
for (let i = 0; i < requests.length; i++) {
462+
const request = requests[i]
463+
errorRequest(this, request, err)
475464
}
476465

477466
client[kPendingIdx] = client[kRunningIdx]
@@ -1089,7 +1078,9 @@ function onSocketClose () {
10891078

10901079
client[kSocket] = null
10911080

1092-
if (client.destroyed) {
1081+
// TODO (fix): Always fail entire queue
1082+
1083+
if (client.destroyed || client[kHTTPConnVersion] === 'h2') {
10931084
assert(client[kPending] === 0)
10941085

10951086
// Fail entire queue.
@@ -1325,8 +1316,10 @@ function _resume (client, sync) {
13251316
return
13261317
}
13271318

1328-
if (client[kRunning] >= (client[kPipelining] || 1)) {
1329-
return
1319+
if (client[kHTTPConnVersion] === 'h1') {
1320+
if (client[kRunning] >= (client[kPipelining] || 1)) {
1321+
return
1322+
}
13301323
}
13311324

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

1356-
if (socket.destroyed || socket[kWriting] || socket[kReset] || socket[kBlocking]) {
1349+
if (socket.destroyed) {
13571350
return
13581351
}
13591352

1360-
if (client[kRunning] > 0 && !request.idempotent) {
1361-
// Non-idempotent request cannot be retried.
1362-
// Ensure that no other requests are inflight and
1363-
// could cause failure.
1364-
return
1365-
}
1353+
if (client[kHTTPConnVersion] === 'h1') {
1354+
if (socket[kWriting] || socket[kReset] || socket[kBlocking]) {
1355+
return
1356+
}
13661357

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

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

1381-
// Request with stream or iterator body cannot be retried.
1382-
// Ensure that no other requests are inflight and
1383-
// could cause failure.
1384-
return
1372+
if (client[kRunning] > 0 && util.bodyLength(request.body) !== 0 &&
1373+
(util.isStream(request.body) || util.isAsyncIterable(request.body) || util.isFormDataLike(request.body))) {
1374+
// Request with stream or iterator body can error while other requests
1375+
// are inflight and indirectly error those as well.
1376+
// Ensure this doesn't happen by waiting for inflight
1377+
// to complete before dispatching.
1378+
1379+
// Request with stream or iterator body cannot be retried.
1380+
// Ensure that no other requests are inflight and
1381+
// could cause failure.
1382+
return
1383+
}
13851384
}
13861385

13871386
if (!request.aborted && write(client, request)) {

0 commit comments

Comments
 (0)