Skip to content

Commit

Permalink
Fix cluster-slots discover race condition again (#2867)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjsimps authored Nov 25, 2024
1 parent 9a3e1c5 commit ffa7d25
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/client/lib/cluster/cluster-slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
Expand Down

0 comments on commit ffa7d25

Please sign in to comment.