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:
parent
ba45367830
commit
f8f6a21580
@ -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.
|
||||
|
21
test/parallel/test-stream-pipe-error-unhandled.js
Normal file
21
test/parallel/test-stream-pipe-error-unhandled.js
Normal 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'));
|
Loading…
Reference in New Issue
Block a user