Skip to content

Commit

Permalink
stream: fix pipeline when a error need to be returned on callback
Browse files Browse the repository at this point in the history
The fix consist in to check a specific case of pipeline

Fix: nodejs#39447
  • Loading branch information
ktfth committed Jul 31, 2021
1 parent d9ccc17 commit 6f507ba
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/internal/streams/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ async function pump(iterable, writable, finish) {
}

function pipeline(...streams) {
let isArray = false;
const callback = once(popCallback(streams));

// stream.pipeline(streams, callback)
if (ArrayIsArray(streams[0]) && streams.length === 1) {
isArray = true;
streams = streams[0];
}

Expand All @@ -178,8 +180,10 @@ function pipeline(...streams) {

let finishCount = 0;

let hasTransform = [];

function finish(err) {
const hasTransform = streams.filter((s) => {
hasTransform = streams.filter((s) => {
try {
const hasTransformContext =
s.constructor.toString().indexOf('Transform') > -1;
Expand All @@ -190,17 +194,18 @@ function pipeline(...streams) {
const hasNotFlush =
s._flush === undefined;
return (
(
hasTransformContext &&
hasNotPassThrough &&
hasNotWritable &&
hasNotFlush
)
hasTransform.length === 0 &&
hasTransformContext &&
hasNotPassThrough &&
hasNotWritable &&
hasNotFlush &&
!isArray
);
} catch {
return false;
}
}).length > 0;
});
hasTransform = hasTransform.length > 0;
if (hasTransform) {
finishCount -= streams.length;
} else if (!hasTransform) {
Expand Down

0 comments on commit 6f507ba

Please sign in to comment.