From e5e9cbb292e64de80a0f1dc3efeeeea74c87c02e Mon Sep 17 00:00:00 2001 From: Jeremy Simpson Date: Mon, 18 Nov 2024 14:30:13 -0600 Subject: [PATCH] Fix cluster-slots discover race condition again --- 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 824cf2ae813..235e15ffe55 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) };