Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: readable throw unhandled error #29806

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will only emit error if not autoDestroy

if (EE.listenerCount(dest, 'error') === 0) {
if (!dest.destroyed) {
errorOrDestroy(dest, er);
mcollina marked this conversation as resolved.
Show resolved Hide resolved
} else {
dest.emit('error', er);
jasnell marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

// 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'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... this ends up changing the semantics of destroy() rather significantly in that prior to this change, subsequent destroy() calls would be non-ops. This is not necessarily a bad thing in that I tend to prefer the notion that most calls on stream objects should fail with an error after destroy() is called. What I'm not certain about, however, is whether this should be direct throw or an emitted throw.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow. All this PR does is to re-emit the already emitted error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in other places we just re-emit (like this) instead of throwing, e.g. https://github.com/nodejs/node/blob/master/lib/internal/streams/legacy.js#L56