Skip to content

Commit

Permalink
fix(cluster): avoid ClusterAllFailedError in certain cases
Browse files Browse the repository at this point in the history
Closes #1330

Revert 8524eea. Before 4.24.1, ioredis asked cluster nodes for cluster slot information when connecting and periodically after connected. If all cluster nodes failed to provide the information (ex all nodes were down), ioredis would raise the "Failed to refresh slots cache" error and reconnect to the cluster (and print debug log Reset with [] ) if it hadn't connected, otherwise (when running periodically) it would just ignore.

After 4.24.1, ioredis will raise and reconnect to the cluster even the cluster has already connected. This change is introduced to make failover detection faster.

However, the commit causes `ClusterAllFailedError` in certain cases so we'll revert this and find other solutions.
  • Loading branch information
leibale committed May 3, 2021
1 parent aafc349 commit aa9c5b1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/cluster/index.ts
Expand Up @@ -266,7 +266,14 @@ class Cluster extends EventEmitter {
this.once("close", closeListener);
this.once("close", this.handleCloseEvent.bind(this));

this.refreshSlotsCache();
this.refreshSlotsCache(
function (err) {
if (err && err.message === "Failed to refresh slots cache.") {
Redis.prototype.silentEmit.call(this, "error", err);
this.connectionPool.reset([]);
}
}.bind(this)
);
this.subscriber.start();
})
.catch((err) => {
Expand Down Expand Up @@ -513,8 +520,6 @@ class Cluster extends EventEmitter {
"Failed to refresh slots cache.",
lastNodeError
);
Redis.prototype.silentEmit.call(_this, "error", error);
_this.connectionPool.reset([]);
return wrapper(error);
}
const node = nodes[index];
Expand Down

0 comments on commit aa9c5b1

Please sign in to comment.