Skip to content

Commit aa9c5b1

Browse files
authored
fix(cluster): avoid ClusterAllFailedError in certain cases
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.
1 parent aafc349 commit aa9c5b1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/cluster/index.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,14 @@ class Cluster extends EventEmitter {
266266
this.once("close", closeListener);
267267
this.once("close", this.handleCloseEvent.bind(this));
268268

269-
this.refreshSlotsCache();
269+
this.refreshSlotsCache(
270+
function (err) {
271+
if (err && err.message === "Failed to refresh slots cache.") {
272+
Redis.prototype.silentEmit.call(this, "error", err);
273+
this.connectionPool.reset([]);
274+
}
275+
}.bind(this)
276+
);
270277
this.subscriber.start();
271278
})
272279
.catch((err) => {
@@ -513,8 +520,6 @@ class Cluster extends EventEmitter {
513520
"Failed to refresh slots cache.",
514521
lastNodeError
515522
);
516-
Redis.prototype.silentEmit.call(_this, "error", error);
517-
_this.connectionPool.reset([]);
518523
return wrapper(error);
519524
}
520525
const node = nodes[index];

0 commit comments

Comments
 (0)