{"record":{"id":"07ead2a547b345b8","repo":"redis/node-redis","slug":"too-many-cluster-redirections","errorCode":null,"errorMessage":"Too many Cluster redirections","messagePattern":"Too many Cluster redirections","errorType":"exception","errorClass":"MaxCommandRedirectionsError","httpStatus":null,"severity":"error","filePath":"packages/client/lib/cluster/index.ts","lineNumber":733,"sourceCode":"          myFn = fn;\n\n          if (!(err instanceof Error)) {\n            throw err;\n          }\n\n          const isRedirect = err.message.startsWith('ASK') || err.message.startsWith('MOVED');\n\n          if (++i > maxCommandRedirections) {\n            publish(CHANNELS.ERROR, () => ({\n              error: err,\n              origin: 'cluster',\n              internal: false,\n              clientId: client._clientId,\n              retryCount: i,\n            }));\n\n            if (isRedirect) {\n              throw new MaxCommandRedirectionsError(err);\n            }\n            throw err;\n          }\n\n          if (err.message.startsWith('ASK')) {\n            publish(CHANNELS.ERROR, () => ({\n              error: err,\n              origin: 'cluster',\n              internal: true,\n              clientId: client._clientId,\n              retryCount: i,\n            }));\n            const address = err.message.substring(err.message.lastIndexOf(' ') + 1);\n            let redirectTo = await this._slots.getMasterByAddress(address);\n            if (!redirectTo) {\n              await this._slots.rediscover(client);\n              redirectTo = await this._slots.getMasterByAddress(address);\n            }","sourceCodeStart":715,"sourceCodeEnd":751,"githubUrl":"https://github.com/redis/node-redis/blob/90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58/packages/client/lib/cluster/index.ts#L715-L751","documentation":"Thrown as MaxCommandRedirectionsError when a single command in the core _execute transport loop receives more MOVED or ASK redirections than the configured limit (default 16). Each redirect means the slot moved to a different node mid-flight; exceeding the ceiling indicates the cluster topology is in a state where redirects chain faster than the client can re-resolve.","triggerScenarios":"Active slot resharding where MOVED responses form a loop (node A redirects to B, B redirects back to A); stale slots table that never updates despite rediscovery calls; ASK redirects during failover where the target node keeps rejecting with further ASKs.","commonSituations":"Heavy resharding in progress; cluster topology split-brain where nodes disagree on slot ownership; proxy or load balancer that mangles MOVED/ASK responses; maxCommandRedirections set too low for a turbulent cluster.","solutions":["Increase `maxCommandRedirections` in the cluster options (default 16) to tolerate more redirect hops","Wait for resharding or failover to complete before retrying","Run CLUSTER NODES / CLUSTER SLOTS on each node to check for topology inconsistencies","If using a proxy, verify it passes MOVED/ASK responses through unchanged"],"exampleFix":"// before — default limit of 16 redirects\nconst cluster = createCluster({ rootNodes: [...] });\n\n// after — raise the ceiling during heavy resharding\nconst cluster = createCluster({\n  rootNodes: [...],\n  maxCommandRedirections: 32\n});","handlingStrategy":"retry","validationCode":null,"typeGuard":"import { MaxCommandRedirectionsError } from '@redis/client/dist/lib/errors';\n\nfunction isMaxRedirections(err: unknown): err is MaxCommandRedirectionsError {\n  return err instanceof MaxCommandRedirectionsError;\n}","tryCatchPattern":"async function withRedirectRetry<T>(fn: () => Promise<T>, maxRetries = 2): Promise<T> {\n  try {\n    return await fn();\n  } catch (err) {\n    if (maxRetries > 0 && err instanceof MaxCommandRedirectionsError) {\n      await new Promise(r => setTimeout(r, 1000));\n      return withRedirectRetry(fn, maxRetries - 1);\n    }\n    throw err;\n  }\n}","preventionTips":["Set maxCommandRedirections higher than 16 in turbulent cluster environments","Avoid heavy traffic during active resharding windows","Monitor CLUSTER INFO for cluster_state=ok and cluster_slots_moving","Verify no proxy or load balancer mangles MOVED/ASK responses"],"tags":["cluster","redirection","resharding","topology"],"backgroundTag":null,"analyzedSha":"90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58","analyzedAt":"2026-08-11T15:37:21.243Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}