You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Fix cluster-slots discover race condition again (#2867)
This commit is contained in:
@@ -164,13 +164,14 @@ export default class RedisClusterSlots<
|
|||||||
}
|
}
|
||||||
|
|
||||||
async #discover(rootNode: RedisClusterClientOptions) {
|
async #discover(rootNode: RedisClusterClientOptions) {
|
||||||
this.#resetSlots();
|
|
||||||
try {
|
try {
|
||||||
const addressesInUse = new Set<string>(),
|
const addressesInUse = new Set<string>(),
|
||||||
promises: Array<Promise<unknown>> = [],
|
promises: Array<Promise<unknown>> = [],
|
||||||
eagerConnect = this.#options.minimizeConnections !== true;
|
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> = {
|
const shard: Shard<M, F, S, RESP, TYPE_MAPPING> = {
|
||||||
master: this.#initiateSlotNode(master, false, eagerConnect, addressesInUse, promises)
|
master: this.#initiateSlotNode(master, false, eagerConnect, addressesInUse, promises)
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user