From 1a8313c169e40bbc6701f068b7e96268955b5f92 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 8 Dec 2021 20:50:50 +0100 Subject: [PATCH 01/19] fix: errored stream is disturbed --- lib/fetch/body.js | 6 +----- lib/fetch/index.js | 6 +++--- test/node-fetch/main.js | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/fetch/body.js b/lib/fetch/body.js index 0cf88af74aa..28c9fcb0759 100644 --- a/lib/fetch/body.js +++ b/lib/fetch/body.js @@ -3,7 +3,7 @@ const util = require('../core/util') const { ReadableStreamFrom, toUSVString, isBlobLike } = require('./util') const { FormData } = require('./formdata') -const { kState, kError } = require('./symbols') +const { kState } = require('./symbols') const { Blob } = require('buffer') const { kBodyUsed } = require('../core/symbols') const assert = require('assert') @@ -268,10 +268,6 @@ const methods = { if (this[kState].body) { const stream = this[kState].body.stream - if (stream[kError]) { - throw stream[kError] - } - if (util.isDisturbed(stream)) { throw new TypeError('disturbed') } diff --git a/lib/fetch/index.js b/lib/fetch/index.js index 476264013ad..22b0f9be61c 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -1531,7 +1531,7 @@ function httpNetworkFetch ( await pullAlgorithm(controller) }, async cancel (reason) { - stream[kError] = reason + this[kError] = reason await cancelAlgorithm(reason) } }, @@ -1742,8 +1742,8 @@ function httpNetworkFetch ( controller.enqueue(new Uint8Array(bytes)) // 8. If stream is errored, then terminate the ongoing fetch. - if (stream[kError]) { - this.context.terminate({ reason: stream[kError] }) + if (controller[kError]) { + this.context.terminate({ reason: controller[kError] }) return } diff --git a/test/node-fetch/main.js b/test/node-fetch/main.js index fbae3ccf935..2bcaa59edb0 100644 --- a/test/node-fetch/main.js +++ b/test/node-fetch/main.js @@ -882,7 +882,7 @@ describe('node-fetch', () => { return expect(res.text()) .to.eventually.be.rejected .and.be.an.instanceof(Error) - .and.have.property('name', 'AbortError') + .and.have.property('name', 'TypeError') }) }) }) From 1671eda7e08484fbcf93152fa7227f7bb8a5c67f Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 8 Dec 2021 20:58:12 +0100 Subject: [PATCH 02/19] fixup --- lib/fetch/index.js | 41 ++++++++++++++++++++--------------------- lib/fetch/symbols.js | 3 +-- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index 22b0f9be61c..2abdc91e4a1 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -31,7 +31,7 @@ const { determineRequestsReferrer, coarsenedSharedCurrentTime } = require('./util') -const { kState, kHeaders, kGuard, kRealm, kError } = require('./symbols') +const { kState, kHeaders, kGuard, kRealm } = require('./symbols') const { AbortError } = require('../core/errors') const assert = require('assert') const { safelyExtractBody, cancelBody } = require('./body') @@ -1516,27 +1516,26 @@ function httpNetworkFetch ( } let pullResolve + let streamError - const stream = new ReadableStream( - { - async start (controller) { - context.controller = controller - }, - async pull (controller) { - if (!pullAlgorithm) { - await new Promise((resolve) => { - pullResolve = resolve - }) - } - await pullAlgorithm(controller) - }, - async cancel (reason) { - this[kError] = reason - await cancelAlgorithm(reason) + const underlyingSource = { + async start (controller) { + context.controller = controller + }, + async pull (controller) { + if (!pullAlgorithm) { + await new Promise((resolve) => { + pullResolve = resolve + }) } + await pullAlgorithm(controller) }, - { highWaterMark } - ) + async cancel (reason) { + streamError = reason + await cancelAlgorithm(reason) + } + } + const stream = new ReadableStream(underlyingSource, { highWaterMark }) // 16. Run these steps, but abort when the ongoing fetch is terminated: // TODO @@ -1742,8 +1741,8 @@ function httpNetworkFetch ( controller.enqueue(new Uint8Array(bytes)) // 8. If stream is errored, then terminate the ongoing fetch. - if (controller[kError]) { - this.context.terminate({ reason: controller[kError] }) + if (streamError) { + this.context.terminate({ reason: streamError }) return } diff --git a/lib/fetch/symbols.js b/lib/fetch/symbols.js index 823a5d3c0c6..0b947d55bad 100644 --- a/lib/fetch/symbols.js +++ b/lib/fetch/symbols.js @@ -6,6 +6,5 @@ module.exports = { kSignal: Symbol('signal'), kState: Symbol('state'), kGuard: Symbol('guard'), - kRealm: Symbol('realm'), - kError: Symbol('error') + kRealm: Symbol('realm') } From 8e317f4621bdf6a421d60f70b2bc2c138e1cf165 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 8 Dec 2021 20:58:37 +0100 Subject: [PATCH 03/19] fixup --- lib/fetch/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index 2abdc91e4a1..f42c0bcd8fb 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -1518,7 +1518,7 @@ function httpNetworkFetch ( let pullResolve let streamError - const underlyingSource = { + const stream = new ReadableStream({ async start (controller) { context.controller = controller }, @@ -1534,8 +1534,7 @@ function httpNetworkFetch ( streamError = reason await cancelAlgorithm(reason) } - } - const stream = new ReadableStream(underlyingSource, { highWaterMark }) + }, { highWaterMark }) // 16. Run these steps, but abort when the ongoing fetch is terminated: // TODO From 08cc40b5a6e197ed9b7a092c4e70e4076c962a15 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 8 Dec 2021 20:58:52 +0100 Subject: [PATCH 04/19] fixup --- lib/fetch/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index f42c0bcd8fb..86f033ecf0b 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -1515,7 +1515,7 @@ function httpNetworkFetch ( ReadableStream = require('stream/web').ReadableStream } - let pullResolve + let streamStart let streamError const stream = new ReadableStream({ @@ -1525,7 +1525,7 @@ function httpNetworkFetch ( async pull (controller) { if (!pullAlgorithm) { await new Promise((resolve) => { - pullResolve = resolve + streamStart = resolve }) } await pullAlgorithm(controller) @@ -1750,9 +1750,9 @@ function httpNetworkFetch ( return controller.desiredSize > 0 } - if (pullResolve) { - pullResolve() - pullResolve = null + if (streamStart) { + streamStart() + streamStart = null } resolve(response) From 656f8f9b1484a1a4925fdf791621a8fbd119887d Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 8 Dec 2021 20:59:26 +0100 Subject: [PATCH 05/19] fixup --- lib/fetch/index.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index 86f033ecf0b..ceabf0c6cdf 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -1518,23 +1518,26 @@ function httpNetworkFetch ( let streamStart let streamError - const stream = new ReadableStream({ - async start (controller) { - context.controller = controller - }, - async pull (controller) { - if (!pullAlgorithm) { - await new Promise((resolve) => { - streamStart = resolve - }) + const stream = new ReadableStream( + { + async start (controller) { + context.controller = controller + }, + async pull (controller) { + if (!pullAlgorithm) { + await new Promise((resolve) => { + streamStart = resolve + }) + } + await pullAlgorithm(controller) + }, + async cancel (reason) { + streamError = reason + await cancelAlgorithm(reason) } - await pullAlgorithm(controller) }, - async cancel (reason) { - streamError = reason - await cancelAlgorithm(reason) - } - }, { highWaterMark }) + { highWaterMark } + ) // 16. Run these steps, but abort when the ongoing fetch is terminated: // TODO From 07d45d5530bb6b8b92e1a30ef2b9f942722cb7c9 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 8 Dec 2021 21:09:48 +0100 Subject: [PATCH 06/19] fixup --- lib/fetch/index.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index ceabf0c6cdf..ce10ebdf515 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -45,6 +45,7 @@ const { const { kHeadersList } = require('../core/symbols') const EE = require('events') const { PassThrough, pipeline, compose } = require('stream') +const nodeUtil = require('util') let ReadableStream @@ -1515,8 +1516,7 @@ function httpNetworkFetch ( ReadableStream = require('stream/web').ReadableStream } - let streamStart - let streamError + let pullResolve const stream = new ReadableStream( { @@ -1526,13 +1526,12 @@ function httpNetworkFetch ( async pull (controller) { if (!pullAlgorithm) { await new Promise((resolve) => { - streamStart = resolve + pullResolve = resolve }) } await pullAlgorithm(controller) }, async cancel (reason) { - streamError = reason await cancelAlgorithm(reason) } }, @@ -1743,8 +1742,8 @@ function httpNetworkFetch ( controller.enqueue(new Uint8Array(bytes)) // 8. If stream is errored, then terminate the ongoing fetch. - if (streamError) { - this.context.terminate({ reason: streamError }) + if (/state: 'errored'/.test(nodeUtil.inspect(stream))) { + this.context.terminate() return } @@ -1753,9 +1752,9 @@ function httpNetworkFetch ( return controller.desiredSize > 0 } - if (streamStart) { - streamStart() - streamStart = null + if (pullResolve) { + pullResolve() + pullResolve = null } resolve(response) From f8f14b6743bd7dc0f7eceb0a4c2779df2a179afa Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 8 Dec 2021 21:10:40 +0100 Subject: [PATCH 07/19] fixup --- lib/fetch/body.js | 1 + lib/fetch/index.js | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/fetch/body.js b/lib/fetch/body.js index 28c9fcb0759..e1b38d7c9b7 100644 --- a/lib/fetch/body.js +++ b/lib/fetch/body.js @@ -187,6 +187,7 @@ function extractBody (object, keepalive = false) { // Whenever one or more bytes are available and stream is not errored, // enqueue a Uint8Array wrapping an ArrayBuffer containing the available // bytes into stream. + // TODO (perf): This check is slow, if (!/state: 'errored'/.test(nodeUtil.inspect(stream))) { controller.enqueue(new Uint8Array(value)) } diff --git a/lib/fetch/index.js b/lib/fetch/index.js index ce10ebdf515..2f2374779d7 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -1742,6 +1742,7 @@ function httpNetworkFetch ( controller.enqueue(new Uint8Array(bytes)) // 8. If stream is errored, then terminate the ongoing fetch. + // TODO (perf): This check is slow, if (/state: 'errored'/.test(nodeUtil.inspect(stream))) { this.context.terminate() return From 00decc2e765e781ba7ded5a7d091acb3602777c9 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 9 Dec 2021 10:39:49 +0100 Subject: [PATCH 08/19] fixup --- lib/core/util.js | 5 +++-- lib/fetch/body.js | 3 ++- lib/fetch/index.js | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index 63f13cbb406..89a9be1066f 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -8,6 +8,7 @@ const net = require('net') const { InvalidArgumentError } = require('./errors') const { Blob } = require('buffer') const nodeUtil = require('util') +const { Stream } = require('stream') function nop () {} @@ -246,7 +247,6 @@ function validateHandler (handler, method, upgrade) { function isDisturbed (body) { const state = body && body._readableState return !!(body && ( - (stream.isDisturbed && stream.isDisturbed(body)) || body[kBodyUsed] || body.readableDidRead || (state && state.dataEmitted) || isAborted(body) @@ -309,7 +309,8 @@ kEnumerableProperty.enumerable = true module.exports = { kEnumerableProperty, nop, - isDisturbed, + isDisturbed: Stream.isDisturbed || isDisturbed, + isErrored: Stream.isErrored || ((body) => /state: 'errored'/.test(nodeUtil.inspect(body))), toUSVString: nodeUtil.toUSVString || ((val) => `${val}`), isAborted, isBlobLike, diff --git a/lib/fetch/body.js b/lib/fetch/body.js index e1b38d7c9b7..ba61cce72a5 100644 --- a/lib/fetch/body.js +++ b/lib/fetch/body.js @@ -9,6 +9,7 @@ const { kBodyUsed } = require('../core/symbols') const assert = require('assert') const nodeUtil = require('util') const { NotSupportedError } = require('../core/errors') +const { isErrored } = require('../core/util') let ReadableStream @@ -188,7 +189,7 @@ function extractBody (object, keepalive = false) { // enqueue a Uint8Array wrapping an ArrayBuffer containing the available // bytes into stream. // TODO (perf): This check is slow, - if (!/state: 'errored'/.test(nodeUtil.inspect(stream))) { + if (!isErrored(stream)) { controller.enqueue(new Uint8Array(value)) } } diff --git a/lib/fetch/index.js b/lib/fetch/index.js index 2f2374779d7..70fbf41fa2e 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -45,7 +45,7 @@ const { const { kHeadersList } = require('../core/symbols') const EE = require('events') const { PassThrough, pipeline, compose } = require('stream') -const nodeUtil = require('util') +const { isErrored } = require('../core/util') let ReadableStream @@ -1743,7 +1743,7 @@ function httpNetworkFetch ( // 8. If stream is errored, then terminate the ongoing fetch. // TODO (perf): This check is slow, - if (/state: 'errored'/.test(nodeUtil.inspect(stream))) { + if (isErrored(stream)) { this.context.terminate() return } From cc98805bba2a9adc414c1b8b0576541f03a867c1 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 9 Dec 2021 10:40:22 +0100 Subject: [PATCH 09/19] fixup --- lib/core/util.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index 89a9be1066f..7a87366ee03 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -8,7 +8,6 @@ const net = require('net') const { InvalidArgumentError } = require('./errors') const { Blob } = require('buffer') const nodeUtil = require('util') -const { Stream } = require('stream') function nop () {} @@ -309,8 +308,8 @@ kEnumerableProperty.enumerable = true module.exports = { kEnumerableProperty, nop, - isDisturbed: Stream.isDisturbed || isDisturbed, - isErrored: Stream.isErrored || ((body) => /state: 'errored'/.test(nodeUtil.inspect(body))), + isDisturbed: stream.isDisturbed || isDisturbed, + isErrored: stream.isErrored || ((body) => /state: 'errored'/.test(nodeUtil.inspect(body))), toUSVString: nodeUtil.toUSVString || ((val) => `${val}`), isAborted, isBlobLike, From fd16ebae2519caaf5fb1ddfb6a3a5ebc6ab6637b Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 9 Dec 2021 10:41:29 +0100 Subject: [PATCH 10/19] fixup --- lib/fetch/body.js | 1 - lib/fetch/index.js | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/fetch/body.js b/lib/fetch/body.js index ba61cce72a5..9a858874958 100644 --- a/lib/fetch/body.js +++ b/lib/fetch/body.js @@ -188,7 +188,6 @@ function extractBody (object, keepalive = false) { // Whenever one or more bytes are available and stream is not errored, // enqueue a Uint8Array wrapping an ArrayBuffer containing the available // bytes into stream. - // TODO (perf): This check is slow, if (!isErrored(stream)) { controller.enqueue(new Uint8Array(value)) } diff --git a/lib/fetch/index.js b/lib/fetch/index.js index 70fbf41fa2e..1a67fbc616d 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -1742,7 +1742,6 @@ function httpNetworkFetch ( controller.enqueue(new Uint8Array(bytes)) // 8. If stream is errored, then terminate the ongoing fetch. - // TODO (perf): This check is slow, if (isErrored(stream)) { this.context.terminate() return From 0f694ebb0a368333c63497d5770651b3208ad92a Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 9 Dec 2021 10:42:22 +0100 Subject: [PATCH 11/19] fixup --- lib/core/util.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/core/util.js b/lib/core/util.js index 7a87366ee03..8cc3ab98485 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -252,6 +252,10 @@ function isDisturbed (body) { )) } +function isErrored (body) { + return body && /state: 'errored'/.test(nodeUtil.inspect(body)) +} + function getSocketInfo (socket) { return { localAddress: socket.localAddress, @@ -309,7 +313,7 @@ module.exports = { kEnumerableProperty, nop, isDisturbed: stream.isDisturbed || isDisturbed, - isErrored: stream.isErrored || ((body) => /state: 'errored'/.test(nodeUtil.inspect(body))), + isErrored: stream.isErrored || isErrored, toUSVString: nodeUtil.toUSVString || ((val) => `${val}`), isAborted, isBlobLike, From cffd81b0a9b468c16fe5a8db745f958b0c08e024 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 9 Dec 2021 15:38:00 +0100 Subject: [PATCH 12/19] fixup --- lib/core/util.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index 8cc3ab98485..ad2c3135e8d 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -244,16 +244,32 @@ function validateHandler (handler, method, upgrade) { // A body is disturbed if it has been read from and it cannot // be re-used without losing state or data. function isDisturbed (body) { + if (!body) { + return false + } + + if (stream.isDisturbed) { + return stream.isDisturbed(body) + } + const state = body && body._readableState - return !!(body && ( + return !!( body[kBodyUsed] || body.readableDidRead || (state && state.dataEmitted) || isAborted(body) - )) + ) } function isErrored (body) { - return body && /state: 'errored'/.test(nodeUtil.inspect(body)) + if (!body) { + return false + } + + if (stream.isErrored) { + return stream.isErrored(body) + } + + return /state: 'errored'/.test(nodeUtil.inspect(body)) } function getSocketInfo (socket) { @@ -312,8 +328,8 @@ kEnumerableProperty.enumerable = true module.exports = { kEnumerableProperty, nop, - isDisturbed: stream.isDisturbed || isDisturbed, - isErrored: stream.isErrored || isErrored, + isDisturbed, + isErrored, toUSVString: nodeUtil.toUSVString || ((val) => `${val}`), isAborted, isBlobLike, From 26e8031fc8885890ceac29f697d916e150c56933 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 9 Dec 2021 15:39:06 +0100 Subject: [PATCH 13/19] fixup --- lib/core/util.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index ad2c3135e8d..373e5ae0f62 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -150,7 +150,7 @@ function isDestroyed (stream) { return !stream || !!(stream.destroyed || stream[kDestroyed]) } -function isAborted (stream) { +function isReadableAborted (stream) { const state = stream && stream._readableState return isDestroyed(stream) && state && !state.endEmitted } @@ -256,7 +256,7 @@ function isDisturbed (body) { return !!( body[kBodyUsed] || body.readableDidRead || (state && state.dataEmitted) || - isAborted(body) + isReadableAborted(body) ) } @@ -331,7 +331,7 @@ module.exports = { isDisturbed, isErrored, toUSVString: nodeUtil.toUSVString || ((val) => `${val}`), - isAborted, + isReadableAborted, isBlobLike, parseOrigin, parseURL, From db666844af630c1a45ab1eb8e9ab3cbeb99ff12d Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 10 Dec 2021 08:53:42 +0100 Subject: [PATCH 14/19] fixup --- lib/core/util.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index 373e5ae0f62..3e10181d648 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -244,20 +244,13 @@ function validateHandler (handler, method, upgrade) { // A body is disturbed if it has been read from and it cannot // be re-used without losing state or data. function isDisturbed (body) { - if (!body) { - return false - } - - if (stream.isDisturbed) { - return stream.isDisturbed(body) - } - const state = body && body._readableState - return !!( + return !!(body && ( + (stream.isDisturbed && stream.isDisturbed(body)) || body[kBodyUsed] || body.readableDidRead || (state && state.dataEmitted) || isReadableAborted(body) - ) + )) } function isErrored (body) { From 6e1d7a0c60f0d523d447f1c35c76d8542859ed6d Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 10 Dec 2021 08:55:41 +0100 Subject: [PATCH 15/19] fixup --- lib/core/util.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index 3e10181d648..2b98d0c3080 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -254,15 +254,10 @@ function isDisturbed (body) { } function isErrored (body) { - if (!body) { - return false - } - - if (stream.isErrored) { - return stream.isErrored(body) - } - - return /state: 'errored'/.test(nodeUtil.inspect(body)) + return !!(body && ( + (stream.isErrored && stream.isErrored(body)) || + /state: 'errored'/.test(nodeUtil.inspect(body)) + )) } function getSocketInfo (socket) { From 017bd46007809b18119828bc4234aaffcffa2c4d Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 10 Dec 2021 13:03:45 +0100 Subject: [PATCH 16/19] fixup --- lib/core/util.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index 2b98d0c3080..5261eea60a5 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -255,9 +255,10 @@ function isDisturbed (body) { function isErrored (body) { return !!(body && ( - (stream.isErrored && stream.isErrored(body)) || - /state: 'errored'/.test(nodeUtil.inspect(body)) - )) + stream.isErrored + ? stream.isErrored(body) + : /state: 'errored'/.test(nodeUtil.inspect(body) + ))) } function getSocketInfo (socket) { From 3160a64c96691891c21dafd2665e1e44d4ec282b Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 10 Dec 2021 13:06:23 +0100 Subject: [PATCH 17/19] fixup --- lib/core/util.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index 5261eea60a5..58912dfb480 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -246,10 +246,12 @@ function validateHandler (handler, method, upgrade) { function isDisturbed (body) { const state = body && body._readableState return !!(body && ( - (stream.isDisturbed && stream.isDisturbed(body)) || - body[kBodyUsed] || - body.readableDidRead || (state && state.dataEmitted) || - isReadableAborted(body) + stream.isDisturbed + ? stream.isDisturbed(body) || body[kBodyUsed] + : body[kBodyUsed] || + body.readableDidRead || + (state && state.dataEmitted) || + isReadableAborted(body) )) } From 4f47b617b47ede4c88bb78f192c82d89edfac627 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 10 Dec 2021 13:25:31 +0100 Subject: [PATCH 18/19] fixup --- lib/core/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/util.js b/lib/core/util.js index 58912dfb480..89007538807 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -247,7 +247,7 @@ function isDisturbed (body) { const state = body && body._readableState return !!(body && ( stream.isDisturbed - ? stream.isDisturbed(body) || body[kBodyUsed] + ? stream.isDisturbed(body) || body[kBodyUsed] // TODO (fix): Why is body[kBodyUsed] needed? : body[kBodyUsed] || body.readableDidRead || (state && state.dataEmitted) || From 2cc7067f74d33fa4bec4a006dd2bef343fcc8b41 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 10 Dec 2021 14:10:08 +0100 Subject: [PATCH 19/19] fixup --- lib/core/util.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index 89007538807..69c7d44434c 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -244,13 +244,12 @@ function validateHandler (handler, method, upgrade) { // A body is disturbed if it has been read from and it cannot // be re-used without losing state or data. function isDisturbed (body) { - const state = body && body._readableState return !!(body && ( stream.isDisturbed ? stream.isDisturbed(body) || body[kBodyUsed] // TODO (fix): Why is body[kBodyUsed] needed? : body[kBodyUsed] || body.readableDidRead || - (state && state.dataEmitted) || + (body._readableState && body._readableState.dataEmitted) || isReadableAborted(body) )) }