Skip to content

Commit

Permalink
Set node status to "reconnecting" until at least one failed reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Rodriguez committed Jul 11, 2012
1 parent fc1a722 commit 389d592
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 12 additions & 0 deletions index.js
Expand Up @@ -434,6 +434,18 @@ RedisHAClient.prototype.parseNodeList = function(nodeList, options) {
}
}
});
node.on('reconnecting', function() {
if (self.isMaster(this)) {
self.warn('MASTER connection dropped, reconnecting...');
}
else {
self.warn(this + ' connection dropped, reconnecting...');
}
self.connected = false;
self.ready = false;
// @todo: pass some real attempts/timers here
self.emit('reconnecting', {});
});
node.on('down', function() {
if (self.isMaster(this)) {
self.error('MASTER is down! (' + this + ')');
Expand Down
12 changes: 10 additions & 2 deletions lib/node.js
Expand Up @@ -66,7 +66,15 @@ Node.prototype.connect = function() {
});
this.client.on('end', function() {
if (!this.closing) {
self.setStatus('down');
self.setStatus('reconnecting');
// Client connection closed without quit(). If reconnection fails, the
// node is considered down.
setTimeout(function waitForReconnect() {
if (!self.client.connected) {
self.emit('error', new Error(self + ' connection dropped and reconnection failed!'));
self.setStatus('down');
}
}, Math.floor(this.retry_delay * this.retry_backoff * 2));
}
});
this.client.on('connect', function() {
Expand All @@ -83,7 +91,7 @@ Node.prototype.connect = function() {
self.setStatus('up');
}
else {
console.warn('WARNING! ' + self.toString() + ' has slave-read-only mode ON, which breaks haredis failover! slave-read-only automatically turned OFF.');
console.warn('WARNING! ' + self + ' has slave-read-only mode ON, which breaks haredis failover! slave-read-only automatically turned OFF.');
self.client.CONFIG('SET', 'slave-read-only', 'no', function(err, reply) {
if (err) {
return self.emit('error', err);
Expand Down

0 comments on commit 389d592

Please sign in to comment.