From 25c7fddafe0802f8f6a14abf13e04870cfa5f0ac Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 1 Oct 2019 23:59:59 +0200 Subject: [PATCH 1/2] stream: readable throw unhandled error If autoDestroy then we should still throw on unhandled errors. --- lib/_stream_readable.js | 9 ++++++-- .../test-stream-pipe-error-unhandled.js | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-stream-pipe-error-unhandled.js diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index eb7d5011d49de2..9e48525f84582e 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -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. diff --git a/test/parallel/test-stream-pipe-error-unhandled.js b/test/parallel/test-stream-pipe-error-unhandled.js new file mode 100644 index 00000000000000..1c4379ca9ef289 --- /dev/null +++ b/test/parallel/test-stream-pipe-error-unhandled.js @@ -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')); From 2cc3fc24eb6db6eaec47f7f5caf187c81b363bf5 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 2 Oct 2019 06:31:26 +0200 Subject: [PATCH 2/2] Update test/parallel/test-stream-pipe-error-unhandled.js Co-Authored-By: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> --- test/parallel/test-stream-pipe-error-unhandled.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-stream-pipe-error-unhandled.js b/test/parallel/test-stream-pipe-error-unhandled.js index 1c4379ca9ef289..42c1ce77fe4878 100644 --- a/test/parallel/test-stream-pipe-error-unhandled.js +++ b/test/parallel/test-stream-pipe-error-unhandled.js @@ -8,7 +8,7 @@ process.on('uncaughtException', common.mustCall((err) => { })); const r = new Readable({ - read () { + read() { this.push('asd'); } });