0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

stream: throw unhandled error for readable with autoDestroy

If autoDestroy then we should still throw on unhandled
errors.

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Robert Nagy 2019-10-01 23:59:59 +02:00 committed by Rich Trott
parent ba45367830
commit f8f6a21580
2 changed files with 28 additions and 2 deletions

View File

@ -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.

View File

@ -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'));