-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Regression in stream.Readable #6007
Comments
Why would this code snippet throw? The first error event (caused by calling the not-implemented Consider this code snippet, which WILL throw: var EE = require('events').EventEmitter;
var R = require('stream').Readable;
var W = require('stream').Writable;
var r = new R;
r._read = function(n) {
r.push(new Buffer('!'));
}
var w = new W;
w.emit = function(orig) { return function(ev, arg) {
if (ev === 'error')
console.error('emit error', EE.listenerCount(w, ev) === 0 ? 'throw': 'catch', arg);
return orig.apply(w, arguments);
}}(w.emit);
function onerror(err) {
console.error('got error', err);
}
w.on('error', onerror);
r.pipe(w);
w.removeListener('error', onerror);
// but this will throw now!
r.pipe(w); // EDIT: Removed the setImmediate, as it's not actually relevant. |
I tested it with the current 0.10.15 release, and a checkout from master. One throws, the other doesn't (and the error listener is never called). |
Expected output (from node v0.10.15):
Output after patch 23d92ec:
|
@isaacs To answer your question directly, the code would throw because the flow start is deferred to Anyway, the why is not relevant, rather the missed error handling caused by the recent patch. I can see that it is also in the pipeline for the current stable branch, and I would appreciate some further feedback on this issue. Feel free to close this if I have misunderstood things, and it is now OK for node to silently ignore errors with no attached listeners. |
Ah, I see. Yes. I was getting confused by the example code. Here's a simpler case: writable.on('error', handler);
readable.pipe(writable);
writable.removeListener('error', handler);
writable.emit('error', new Error('this should throw')); Fixed by pull req #6075 |
The following code snippet no longer throws after 23d92ec from #5996. I suggest replacing it with my actual fix from #4978.
The text was updated successfully, but these errors were encountered: