Skip to content

fix(redis): Retry cluster client creation when no startup node is reachable - #132097

Draft
sentry-junior[bot] wants to merge 3 commits into
masterfrom
fix/retry-redis-cluster-slots-init
Draft

sentry-junior[bot] wants to merge 3 commits into
masterfrom
fix/retry-redis-cluster-slots-init

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

A short network blip can leave every Redis Cluster startup node unreachable. When that happens, redis-py-cluster raises RedisClusterException: Redis Cluster cannot be connected while the client is being created, and whatever first touched the lazy client fails with it. That can be a task, a consumer, a request, or bookkeeping in the middle of a write where retrying the whole unit of work isn't an option.

cluster_factory now builds the client through _create_cluster_with_retry. On the "cannot be connected" error, it retries the RetryingRedisCluster(...) call once, right away. There's no sleep, because a failed attempt has usually already waited out socket_timeout (3s) on each unreachable startup node. Creating a client only reads cluster topology (CLUSTER SLOTS), so the retry can't double-apply a caller's write. The retry re-copies the startup nodes, because redis-py-cluster mutates them. Each retry increments redis.cluster.create.retry.

redis.cluster.create-retry.enabled (default True, automator-modifiable) is a kill switch: if the retry makes an outage worse, it can be turned off without a deploy. The option is only read after a failed first attempt.

This covers creating the client only. Slot refreshes on a client that already exists (reset() after connection errors, and reinitialization from commands and pipelines) still raise right away.

Open decision:

  • Matching on the message. redis-py-cluster raises a bare RedisClusterException for every case, so this keys off the message prefix. Other creation failures, such as slot disagreement or incomplete coverage, still raise right away. If an attempt fails fast instead of timing out (for example connection refused), the retry happens almost immediately, with no real delay.

via @kcons.

--

View Session [Sentry]

A short network blip can leave every Redis Cluster startup node unreachable, which fails CLUSTER SLOTS and the work that triggered it. Retry NodeManager.initialize twice with a short jittered backoff when that happens. CLUSTER SLOTS is read-only, so the retry is safe even mid-write.

Co-Authored-By: Kyle Consalus <6990351+kcons@users.noreply.github.com>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 21, 2026
Comment thread src/sentry/utils/redis.py Resolved
…ager

Build the cluster client through a small retrying constructor rather than patching the node manager's initialize method on each client.
@sentry-junior sentry-junior Bot changed the title fix(redis): Retry cluster slots init when no startup node is reachable fix(redis): Retry cluster client creation when no startup node is reachable Nov 21, 2026
… switch

A failed attempt has usually already waited out the socket timeout on each unreachable startup node, so retry once immediately. Add redis.cluster.create-retry.enabled so the retry can be turned off without a deploy.

Co-Authored-By: Kyle Consalus <6990351+kcons@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant