Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: fix pipeline calling end on destination more than once #46226

Merged
merged 3 commits into from Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/streams/pipeline.js
Expand Up @@ -353,7 +353,7 @@ function pipe(src, dst, finish, { end }) {
}
});

src.pipe(dst, { end });
src.pipe(dst, { end: false }); // If end is true we already will have a listener to end 'dst'.
debadree25 marked this conversation as resolved.
Show resolved Hide resolved

if (end) {
// Compat. Before node v10.12.0 stdio used to throw an error so
Expand Down
35 changes: 35 additions & 0 deletions test/parallel/test-stream-pipeline.js
Expand Up @@ -1556,3 +1556,38 @@ const tsp = require('timers/promises');
})
);
}

{
class CustomReadable extends Readable {
_read() {
this.push('asd');
this.push(null);
}
}

class CustomWritable extends Writable {
constructor() {
super();
this.endCount = 0;
this.str = '';
}

_write(chunk, enc, cb) {
this.str += chunk;
cb();
}

end() {
this.endCount += 1;
super.end();
}
}

const readable = new CustomReadable();
const writable = new CustomWritable();

pipeline(readable, writable, common.mustSucceed(() => {
assert.strictEqual(writable.str, 'asd');
assert.strictEqual(writable.endCount, 1);
}));
}