diff options
author | Felix Geisendörfer <felix@debuggable.com> | 2011-05-23 11:02:53 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-05-24 10:50:33 -0700 |
commit | 2b91256c6185fbcaaa5fc49a3a541e5ed0ec0e75 (patch) | |
tree | 28ac12f4ae15422ec5fe2804895384420dfaabd9 /lib/stream.js | |
parent | d22259426c900f0083513d8b43c250792a5ca7f7 (diff) | |
download | nodejs-2b91256c6185fbcaaa5fc49a3a541e5ed0ec0e75.tar.gz nodejs-2b91256c6185fbcaaa5fc49a3a541e5ed0ec0e75.tar.bz2 nodejs-2b91256c6185fbcaaa5fc49a3a541e5ed0ec0e75.zip |
Fix error handling bug in stream.pipe()
Problem: Since stream.pipe() is registering it's own error handlers on
the source and destination stream, it needs to replicate the
EventEmitter 'error' emitting semantics of throwing an error if there
are no other listeners. However, there was a off-by-one error because
the check for remaining listeners was done after cleanup() which means
the pipe's own listener was no longer included.
This would cause 'error' events on either the dest or the source to
throw if there was one other error listener, and while swallowing
the 'error' event if there was no other listener.
Solution: I added a test demonstrating the two issues and fixed the
problem by correcting the off-by-one error.
Fixes #1095.
Diffstat (limited to 'lib/stream.js')
-rw-r--r-- | lib/stream.js | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/stream.js b/lib/stream.js index a5b797482..1ad08ec14 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -95,7 +95,7 @@ Stream.prototype.pipe = function(dest, options) { // don't leave dangling pipes when there are errors. function onerror(er) { cleanup(); - if (this.listeners('error').length === 1) { + if (this.listeners('error').length === 0) { throw er; // Unhandled stream error in pipe. } } |