Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2019-12-21 14:08:36 +0300
committerRich Trott <rtrott@gmail.com>2019-12-25 23:50:30 +0300
commitc852f7e2ac3a071245a4080f0e2d7fdc18aec6b4 (patch)
tree92dfa1dad8f67b841f306a4099fa89e0532b0105 /lib
parent2c5d35ee1ee86c4099f036c004f2b60033c7b8bc (diff)
stream: pipeline should use req.abort() to destroy response
destroy(err) on http response will propagate the error to the request causing 'error' to be unexpectedly emitted. Furthermore, response.destroy() unlike request.abort() does not _dump buffered data. Fixes a breaking change introduced in https://github.com/nodejs/node/commit/648088289d619bfb149fe90316ce0127083c4c99. Prefer res.req.abort() over res.destroy() until this situation is clarified. Fixes: https://github.com/nodejs/node/issues/31029 Refs: https://github.com/nodejs/node/commit/648088289d619bfb149fe90316ce0127083c4c99 PR-URL: https://github.com/nodejs/node/pull/31054 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/streams/pipeline.js15
1 files changed, 3 insertions, 12 deletions
diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js
index ed5556e5d0a..92a91c30171 100644
--- a/lib/internal/streams/pipeline.js
+++ b/lib/internal/streams/pipeline.js
@@ -17,7 +17,7 @@ const {
} = require('internal/errors').codes;
function isRequest(stream) {
- return stream.setHeader && typeof stream.abort === 'function';
+ return stream && stream.setHeader && typeof stream.abort === 'function';
}
function destroyer(stream, reading, writing, callback) {
@@ -43,22 +43,13 @@ function destroyer(stream, reading, writing, callback) {
// request.destroy just do .end - .abort is what we want
if (isRequest(stream)) return stream.abort();
- if (typeof stream.destroy === 'function') {
- if (stream.req && stream._writableState === undefined) {
- // This is a ClientRequest
- // TODO(mcollina): backward compatible fix to avoid crashing.
- // Possibly remove in a later semver-major change.
- stream.req.on('error', noop);
- }
- return stream.destroy(err);
- }
+ if (isRequest(stream.req)) return stream.req.abort();
+ if (typeof stream.destroy === 'function') return stream.destroy(err);
callback(err || new ERR_STREAM_DESTROYED('pipe'));
};
}
-function noop() {}
-
function pipe(from, to) {
return from.pipe(to);
}