From ffa7d2525c6d8bdd24faaad527a3ad0aec2cd8e9 Mon Sep 17 00:00:00 2001 From: Jeremy <98552694+jjsimps@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:36:33 -0600 Subject: [PATCH] Fix cluster-slots discover race condition again (#2867) --- packages/client/lib/cluster/cluster-slots.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/client/lib/cluster/cluster-slots.ts b/packages/client/lib/cluster/cluster-slots.ts index 10c2c9d306..3a4adff73c 100644 --- a/packages/client/lib/cluster/cluster-slots.ts +++ b/packages/client/lib/cluster/cluster-slots.ts @@ -164,13 +164,14 @@ export default class RedisClusterSlots< } async #discover(rootNode: RedisClusterClientOptions) { - this.#resetSlots(); try { const addressesInUse = new Set(), promises: Array> = [], 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 = { master: this.#initiateSlotNode(master, false, eagerConnect, addressesInUse, promises) };