Skip to content

Commit ffa7d25

Browse files
authored
Fix cluster-slots discover race condition again (#2867)
1 parent 9a3e1c5 commit ffa7d25

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/client/lib/cluster/cluster-slots.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,14 @@ export default class RedisClusterSlots<
164164
}
165165

166166
async #discover(rootNode: RedisClusterClientOptions) {
167-
this.#resetSlots();
168167
try {
169168
const addressesInUse = new Set<string>(),
170169
promises: Array<Promise<unknown>> = [],
171170
eagerConnect = this.#options.minimizeConnections !== true;
172171

173-
for (const { from, to, master, replicas } of await this.#getShards(rootNode)) {
172+
const shards = await this.#getShards(rootNode);
173+
this.#resetSlots(); // Reset slots AFTER shards have been fetched to prevent a race condition
174+
for (const { from, to, master, replicas } of shards) {
174175
const shard: Shard<M, F, S, RESP, TYPE_MAPPING> = {
175176
master: this.#initiateSlotNode(master, false, eagerConnect, addressesInUse, promises)
176177
};

0 commit comments

Comments
 (0)