Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/internal/streams/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ function destroyer(stream, reading, writing, callback) {
closed = true;
});

stream.on('error', () => {
// Pipeline should not allow uncaught stream errors to propagate.
// 1. eos can complete before 'close' (e.g. 'finish' or 'end')
// and therefore 'error' can be emitted after eos.
// 2. Buggy streams can emit 'error' after 'close'
});

if (eos === undefined) eos = require('internal/streams/end-of-stream');
eos(stream, { readable: reading, writable: writing }, (err) => {
eos(stream, { readable: reading, writable: writing, error: false }, (err) => {
if (err) return callback(err);
closed = true;
callback();
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,22 @@ const { promisify } = require('util');
{ code: 'ERR_INVALID_CALLBACK' }
);
}

{
const read = new Readable({
read() {}
});

const write = new Writable({
write(data, enc, cb) {
cb();
}
});

read.push(null);
pipeline(read, write, common.mustCall(err => {
// Should swallow unexpected errors.
read.emit('error', new Error());
write.emit('error', new Error());
}));
}