Skip to content

Commit

Permalink
Fix an issue where too many error listeners would be attached to a ch…
Browse files Browse the repository at this point in the history
…annel when publishing messages quickly.
  • Loading branch information
ssafejava committed Aug 30, 2013
1 parent 8f5f70d commit 8448e49
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var methods = definitions.methods;
// of Channel. This just provides a task queue.
var Channel = module.exports = function Channel (connection, channel) {
events.EventEmitter.call(this);
// Unlimited listeners. Helps when e.g. publishing high-volume messages, 10 is far too low.
this.setMaxListeners(0);

this.channel = channel;
this.connection = connection;
Expand Down
9 changes: 4 additions & 5 deletions lib/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,16 @@ Exchange.prototype.publish = function (routingKey, data, options, callback) {
self._sequence++;

if(callback != null){
var errorCallback = function(){
var errorCallback = function(err){
task.removeAllListeners();
callback(true);
callback(true, err);
};
var exchange = this;
task.once('ack', function(){
exchange.removeListener('error', errorCallback);
self.removeListener('error', errorCallback);
task.removeAllListeners();
callback(false);
});
this.once('error', errorCallback);
self.once('error', errorCallback);
}
}

Expand Down

0 comments on commit 8448e49

Please sign in to comment.