Skip to content

Commit

Permalink
stream: throw unhandled error for readable with autoDestroy
Browse files Browse the repository at this point in the history
If autoDestroy then we should still throw on unhandled
errors.

PR-URL: #29806
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Co-Authored-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
2 people authored and Trott committed Oct 13, 2019
1 parent ba45367 commit f8f6a21
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 f8f6a21

Please sign in to comment.