-
Notifications
You must be signed in to change notification settings - Fork 7.3k
streams.js line 81 (v0.8.11) emits error incorrectly #4155
Comments
Desired or not this is error prone. |
No, but it falls out that way because of how |
/cc @isaacs - maybe his streams2 work can address this. |
Hi. I got bitten by this issue recently and tried to think about what could be done to fix it. I see two ways: Change the semantics of
|
@spion a modified |
@kanogil yeah, we could use that to get the old broken behavior, if we really need it. The immediate removal will be explicit, inside the listener code. On the other hand, to get the new and improved behavior (one-time listeners that can see eachother) we can just use "once". Finally if we want to use the underlying scheduledForDeletion mechanism, it can be exposed through the EventEmitter API. Maybe Edit: Or how about making removeListener schedule removals for later if called in the middle of the event? |
Specifically, if an error listener is attached to a stream _before_ it is piped to, _and_ it cleans up efter itself by removing the error listener, the pipe logic will miss this and throw as if it was unhandled. Fixes nodejs#4155.
Hello,
In some basic network server testing, I found that using
.pipe
and.once('error')
correctly is crazy for consumers. The order in which you call.pipe
and.once('error')
dictates whether your program will exit with an uncaughtException or not. I found this withEPIPE
and long-running server "things" sending data back to a client, but here's a trivial repro case:The streams.js implementation of pipe does a check for
listeners.length
on error, and rethrows an error if there's nothing listening. And, it is common to use .once on 'error' and 'end', since those are expected to indicate "cleanup", and it's fairly easy to cause memory leaks by leaving listeners around with.on
. So, with the illustration above, if the listener call is attached before pipe, the.once
logic removes the error, and pipe rethrows, even though the program correctly caught the error.Is this intended behavior?
The text was updated successfully, but these errors were encountered: