Permalink
Browse files

Adding retry logic in the case of an ETIMEDOUT socket error

  • Loading branch information...
1 parent c60b696 commit 9c8e809dcde613dc44323b831f63dff6dd005c9d @mmattozzi committed Oct 5, 2012
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/irc.js
View
@@ -577,7 +577,16 @@ Client.prototype.connect = function ( retryCount, callback ) { // {{{
}, self.opt.retryDelay );
});
self.conn.addListener("error", function(exception) {
- self.emit("netError", exception);
+ util.log('Connection got "error" event with exception: ' + exception);
+ if (exception.message.match(/ETIMEDOUT/)) {
+ util.log("Responding to ETIMEDOUT socket error by disconnecting, reconnecting");
+ self.disconnect('Disconnecting because of socket ETIMEDOUT');
+ setTimeout( function() {
+ self.connect( retryCount + 1 );
+ }, self.opt.retryDelay );
+ } else {
+ self.emit("netError", exception);
+ }
});
}; // }}}
Client.prototype.disconnect = function ( message, callback ) { // {{{

0 comments on commit 9c8e809

Please sign in to comment.