Skip to content

Commit 633fffe

Browse files
committed
stream: pipeline uncaught error
1 parent 9949fbd commit 633fffe

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/internal/streams/pipeline.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@ function destroyer(stream, reading, writing, callback) {
2424
closed = true;
2525
});
2626

27+
stream.on('error', () => {
28+
// Pipeline should not allow uncaught stream errors to propagate.
29+
// 1. eos can complete before 'close' (e.g. 'finish' or 'end')
30+
// and therefore 'error' can be emitted after eos.
31+
// 2. Buggy streams can emit 'error' after 'close'
32+
});
33+
2734
if (eos === undefined) eos = require('internal/streams/end-of-stream');
28-
eos(stream, { readable: reading, writable: writing }, (err) => {
35+
eos(stream, { readable: reading, writable: writing, error: false }, (err) => {
2936
if (err) return callback(err);
3037
closed = true;
3138
callback();

test/parallel/test-stream-pipeline.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,22 @@ const { promisify } = require('util');
477477
{ code: 'ERR_INVALID_CALLBACK' }
478478
);
479479
}
480+
481+
{
482+
const read = new Readable({
483+
read() {}
484+
});
485+
486+
const write = new Writable({
487+
write(data, enc, cb) {
488+
cb();
489+
}
490+
});
491+
492+
read.push(null);
493+
pipeline(read, write, common.mustCall(err => {
494+
// Should swallow unexpected errors.
495+
read.emit('error', new Error());
496+
write.emit('error', new Error());
497+
}));
498+
}

0 commit comments

Comments
 (0)