Skip to content

Commit

Permalink
fix: "MOVED" err not crashing process when slot was not assigned
Browse files Browse the repository at this point in the history
If slot was not previously discovered by ioredis - it would cause a crash as it
would try to rewrite a masterNode on a missing object
  • Loading branch information
AVVS committed Jan 22, 2016
1 parent 1e26631 commit 6974d4d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,19 +411,26 @@ Cluster.prototype.sendCommand = function (command, stream, node) {
var _this = this;
if (!node) {
command.reject = function (err) {
var partialTry = _.partial(tryConnection, true);

_this.handleError(err, ttl, {
moved: function (node, slot, hostPort) {
debug('command %s is moved to %s:%s', command.name, hostPort[0], hostPort[1]);
_this.slots[slot].masterNode = node;
var coveredSlot = _this.slots[slot];
if (!coveredSlot) {
_this.slots[slot] = { masterNode: node, allNodes: [node] };
} else {
coveredSlot.masterNode = node;
}
tryConnection();
_this.refreshSlotsCache();
},
ask: function (node, slot, hostPort) {
debug('command %s is required to ask %s:%s', command.name, hostPort[0], hostPort[1]);
tryConnection(false, node);
},
clusterDown: tryConnection.bind(null, true),
connectionClosed: tryConnection.bind(null, true),
clusterDown: partialTry,
connectionClosed: partialTry,
maxRedirections: function (redirectionError) {
reject.call(command, redirectionError);
},
Expand Down

0 comments on commit 6974d4d

Please sign in to comment.