Skip to content

Commit f8f6a21

Browse files
ronagtrivikr
authored andcommitted
stream: throw unhandled error for readable with autoDestroy
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>
1 parent ba45367 commit f8f6a21

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

lib/_stream_readable.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,13 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
777777
debug('onerror', er);
778778
unpipe();
779779
dest.removeListener('error', onerror);
780-
if (EE.listenerCount(dest, 'error') === 0)
781-
errorOrDestroy(dest, er);
780+
if (EE.listenerCount(dest, 'error') === 0) {
781+
if (!dest.destroyed) {
782+
errorOrDestroy(dest, er);
783+
} else {
784+
dest.emit('error', er);
785+
}
786+
}
782787
}
783788

784789
// Make sure our error handler is attached before userland ones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const { Readable, Writable } = require('stream');
5+
6+
process.on('uncaughtException', common.mustCall((err) => {
7+
assert.strictEqual(err.message, 'asd');
8+
}));
9+
10+
const r = new Readable({
11+
read() {
12+
this.push('asd');
13+
}
14+
});
15+
const w = new Writable({
16+
autoDestroy: true,
17+
write() {}
18+
});
19+
20+
r.pipe(w);
21+
w.destroy(new Error('asd'));

0 commit comments

Comments
 (0)