From a273dacb03bd674dc66d444435a67d220db4819f Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 6 Apr 2020 20:11:33 +0200 Subject: [PATCH] stream: cleanup pipeline destroyer Slightly cleans up the destroyer logic. --- lib/internal/streams/pipeline.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index fdba5ebc737206..2230e1817955aa 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -41,7 +41,7 @@ function isOutgoing(stream) { ); } -function destroyer(stream, reading, writing, final, callback) { +function destroyer(stream, reading, writing, callback) { const _destroy = once((err) => { if (!err && (isIncoming(stream) || isOutgoing(stream))) { // http/1 request objects have a coupling to their response and should @@ -54,9 +54,11 @@ function destroyer(stream, reading, writing, final, callback) { return callback(); } - if (err || !final || !stream.readable) { - destroyImpl.destroyer(stream, err); + if (!err && !reading && writing && stream.readable) { + return callback(); } + + destroyImpl.destroyer(stream, err); callback(err); }); @@ -204,7 +206,7 @@ function pipeline(...streams) { if (isStream(stream)) { finishCount++; - destroys.push(destroyer(stream, reading, writing, !reading, finish)); + destroys.push(destroyer(stream, reading, writing, finish)); } if (i === 0) { @@ -262,7 +264,7 @@ function pipeline(...streams) { ret = pt; finishCount++; - destroys.push(destroyer(ret, false, true, true, finish)); + destroys.push(destroyer(ret, false, true, finish)); } } else if (isStream(stream)) { if (isReadable(ret)) {