summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEran Hammer <eran@hueniverse.com>2013-08-05 02:56:40 -0700
committerisaacs <i@izs.me>2013-08-06 08:15:13 -0700
commit23d92ec88e0dfe4c2224a2ec4a67ae1ca2bd448d (patch)
treeb3b0672e58415c8c9714637e41a221d35db5a7d9 /lib
parent366baedfd8bbdaa24f85d173125ee31d7f447c62 (diff)
downloadandroid-node-v8-23d92ec88e0dfe4c2224a2ec4a67ae1ca2bd448d.tar.gz
android-node-v8-23d92ec88e0dfe4c2224a2ec4a67ae1ca2bd448d.tar.bz2
android-node-v8-23d92ec88e0dfe4c2224a2ec4a67ae1ca2bd448d.zip
stream: Fix double pipe error emit
If an error listener is added to a stream using once() before it is piped, it is invoked and removed during pipe() but before pipe() sees it which causes it to be emitted again. Fixes #4155 #4978
Diffstat (limited to 'lib')
-rwxr-xr-x[-rw-r--r--]lib/_stream_readable.js4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 2259d2e778..f35599f455 100644..100755
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -511,9 +511,11 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
// if the dest has an error, then stop piping into it.
// however, don't suppress the throwing behavior for this.
+ // check for listeners before emit removes one-time listeners.
+ var errListeners = EE.listenerCount(dest, 'error');
function onerror(er) {
unpipe();
- if (EE.listenerCount(dest, 'error') === 0)
+ if (errListeners === 0 && EE.listenerCount(dest, 'error') === 0)
dest.emit('error', er);
}
dest.once('error', onerror);