Skip to content

Commit

Permalink
stream: readable throw unhandled error
Browse files Browse the repository at this point in the history
If autoDestroy then we should still throw on unhandled
errors.
  • Loading branch information
ronag committed Oct 1, 2019
1 parent f663b31 commit 25c7fdd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,13 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
debug('onerror', er);
unpipe();
dest.removeListener('error', onerror);
if (EE.listenerCount(dest, 'error') === 0)
errorOrDestroy(dest, er);
if (EE.listenerCount(dest, 'error') === 0) {
if (!dest.destroyed) {
errorOrDestroy(dest, er);
} else {
dest.emit('error', er);
}
}
}

// Make sure our error handler is attached before userland ones.
Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-stream-pipe-error-unhandled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { Readable, Writable } = require('stream');

process.on('uncaughtException', common.mustCall((err) => {
assert.strictEqual(err.message, 'asd');
}));

const r = new Readable({
read () {
this.push('asd');
}
});
const w = new Writable({
autoDestroy: true,
write() {}
});

r.pipe(w);
w.destroy(new Error('asd'));

0 comments on commit 25c7fdd

Please sign in to comment.