Skip to content

Commit 6974d4d

Browse files
committed
fix: "MOVED" err not crashing process when slot was not assigned
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
1 parent 1e26631 commit 6974d4d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/cluster.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -411,19 +411,26 @@ Cluster.prototype.sendCommand = function (command, stream, node) {
411411
var _this = this;
412412
if (!node) {
413413
command.reject = function (err) {
414+
var partialTry = _.partial(tryConnection, true);
415+
414416
_this.handleError(err, ttl, {
415417
moved: function (node, slot, hostPort) {
416418
debug('command %s is moved to %s:%s', command.name, hostPort[0], hostPort[1]);
417-
_this.slots[slot].masterNode = node;
419+
var coveredSlot = _this.slots[slot];
420+
if (!coveredSlot) {
421+
_this.slots[slot] = { masterNode: node, allNodes: [node] };
422+
} else {
423+
coveredSlot.masterNode = node;
424+
}
418425
tryConnection();
419426
_this.refreshSlotsCache();
420427
},
421428
ask: function (node, slot, hostPort) {
422429
debug('command %s is required to ask %s:%s', command.name, hostPort[0], hostPort[1]);
423430
tryConnection(false, node);
424431
},
425-
clusterDown: tryConnection.bind(null, true),
426-
connectionClosed: tryConnection.bind(null, true),
432+
clusterDown: partialTry,
433+
connectionClosed: partialTry,
427434
maxRedirections: function (redirectionError) {
428435
reject.call(command, redirectionError);
429436
},

0 commit comments

Comments
 (0)