1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00

Fix cluster-slots discover race condition again (#2867)

This commit is contained in:
Jeremy
2024-11-25 14:36:33 -06:00
committed by GitHub
parent 9a3e1c5e03
commit ffa7d2525c

View File

@@ -164,13 +164,14 @@ export default class RedisClusterSlots<
}
async #discover(rootNode: RedisClusterClientOptions) {
this.#resetSlots();
try {
const addressesInUse = new Set<string>(),
promises: Array<Promise<unknown>> = [],
eagerConnect = this.#options.minimizeConnections !== true;
for (const { from, to, master, replicas } of await this.#getShards(rootNode)) {
const shards = await this.#getShards(rootNode);
this.#resetSlots(); // Reset slots AFTER shards have been fetched to prevent a race condition
for (const { from, to, master, replicas } of shards) {
const shard: Shard<M, F, S, RESP, TYPE_MAPPING> = {
master: this.#initiateSlotNode(master, false, eagerConnect, addressesInUse, promises)
};