Skip to content

Commit

Permalink
Fix race condition in refresh by not connecting until resolver is com…
Browse files Browse the repository at this point in the history
…plete.

The resolver needs to run before the place to connect is determined, but
node-redis will start attempting to reconnect immediately. Prevent this by
setting the port and ip to the empty string and letting the resolver
modify it.

A better fix would be to modify node-redis to be able to not retry until
told to do so.
  • Loading branch information
ldm5180 committed Nov 29, 2014
1 parent 942c0ce commit 2acd9ac
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,17 @@ Sentinel.prototype.createClientInternal = function(masterName, opts) {
client.on('reconnecting', refreshEndpoints);

function refreshEndpoints() {
client.connectionOption.port = "";
client.connectionOption.host = "";
resolver(self.endpoints, masterName, function(_err, ip, port) {
if (_err) { oldEmit.call(client, 'error', _err); }
// Try and reconnect
client.connectionOption.port = port;
client.connectionOption.host = ip;
if (_err) {
oldEmit.call(client, 'error', _err);
} else {
// Try reconnecting.
client.connectionOption.port = port;
client.connectionOption.host = ip;
client.connection_gone("sentinel induced refresh");
}
});
}

Expand Down

0 comments on commit 2acd9ac

Please sign in to comment.