Repository navigation
Description
TLDR: enableAutoPipelining does not work correctly with dynamic clusters (resharding, slot migration, failover). If your cluster topology changes at runtime, autopipelining will cause command failures that would not occur without it.
Summary
When enableAutoPipelining is used with Redis.Cluster, topology changes (slot migration, reshard, failover) can cause entire batches of autopipelined commands to fail. The core issue is that autopipelines group commands for different slots into a single pipeline, but MOVED errors are handled at the pipeline level rather than per-command.
Background
Autopipelining groups commands by node: all commands whose slots are served by the same set of nodes end up in one pipeline. A single autopipeline typically contains commands targeting many different slots.
For individual (non-pipelined) commands, the cluster client handles MOVED errors transparently - it catches the redirect, updates routing, and retries the command to the correct node. The application never sees MOVED errors.
Problem
Consider a topology change where slot 200 migrates from Node A to Node C, while slot 100 stays on Node A:
- Autopipelining groups commands for slots 100 and 200 together (both served by Node A at the time of batching)
- The pipeline sends everything to Node A
- Slot 100 commands succeed, slot 200 commands come back with
MOVED 200 NodeC:port
What happens next depends on the command mix:
Failure Mode 1: Pipelines with writes
If any successful command is a write (SET, INCR, etc.), the pipeline considers itself non-retriable and returns individual results as-is. Successful commands resolve normally, but MOVED commands bubble up as raw errors to the application.
This is unexpected - applications don't expect to see MOVED errors since the cluster client handles them transparently for individual commands.
In this path the entire MOVED handling block is bypassed: no slot mapping updates, no refreshSlotsCache() call. The stale slot map persists, so subsequent autopipeline batches keep getting routed to the wrong node and keep hitting the same MOVED errors. Since slotsRefreshInterval is not configured by default, the map stays stale until something external triggers a refresh (e.g., a non-autopipelined command hitting MOVED).
Failure Mode 2: Read-only pipelines (worse)
If all successful commands are reads, the pipeline considers itself retriable. It parses the commonError message, updates the mapping for that one slot (slot 200 now points to Node C), and re-runs exec(). But the slot map is now only partially corrected - the moved handler calls refreshSlotsCache(), but it's async (sends CLUSTER SLOTS to a node), while the retry exec() runs synchronously right after, before the full topology arrives.
On retry, generateMultiWithNodes sees that slots 100 and 200 now belong to different allocation groups and rejects the pipeline with "All keys in the pipeline should belong to the same slots allocation group".
All commands fail - including the reads that already succeeded on the first attempt. The retry made things strictly worse.
While a pipeline is going through retries, _runningAutoPipelines keeps the slot key locked. New commands for the same slot queue up. After the current pipeline finally fails, the queued commands form a new batch that hits the same stale routing and fails again.
Activity
PavelPashov commentedon Feb 9, 2026
Hey @ivoronin, thanks for reporting this.
We’ll take a look on our side. This PR possibly addresses the
“All keys in the pipeline should belong to the same slots allocation group”issue in some replica/auto-pipelining setups, however it has not been released yet.Also could you share a minimal reproducible code example?
ivoronin commentedon Feb 9, 2026
Here is an example server and client (Grafana k6 load testing script) I've used to reproduce the issue in an ElastiCache environment: https://gist.github.com/ivoronin/c4ebaf35208d6e6217a72ec879273119
The main idea is just hitting Redis with a mix of SET/GET commands; nothing special is required to reproduce the issue - just add/remove a few shards during the load test.
PavelPashov commentedon Sep 15, 2026
@Bubblegunn Thank you for the reproduction and investigation! Yes, a contribution preserving node-based batching and handling
MOVEDcommands individually would be welcome. Before starting a PR, could you share your proposed approach here so we can discuss retry behavior and edge cases and agree on the scope together?PavelPashov commentedon Sep 24, 2026
@Bubblegunn thanks for the detailed proposal and the correction. Keeping node-based batching and retrying only the commands that return
MOVED,ASK, orTRYAGAINsounds reasonable to me.Could we reuse Cluster's single-command retry logic here? Child pipelines would keep retries batched, but retrying each command independently seems easier to maintain. We'd need to share the full recovery behavior, including how it finds and connects to the right node, so the first redirect gets the same handling as later ones.
A few things I'd want us to keep in mind:
ASK, sendASKINGand the command directly to the requested node without changing slot ownership.CLUSTERDOWNand connection loss.I'd be comfortable with one focused PR covering this.
Does this approach seem workable? Is there a case where we'd need child pipelines to preserve performance or ordering?
PavelPashov commentedon Sep 30, 2026
@Bubblegunn Thanks for checking this. I’d prefer to match the existing single-command recovery behavior.
Auto-pipelining is a transport optimization. It should not guarantee the final order of independently issued commands when one needs a retry. If an application requires those writes to execute in a defined order, it should use
MULTI/EXECwhere the commands can run in one transaction.Please document this ordering limitation. I don’t think we need a special retry restriction for overlapping writes.
fix(cluster): resend only the redirected command in a pipeline (redis…
chore(release): 6.1.0 [skip ci]
github-actions commentedon Nov 23, 2026
🎉 This issue has been resolved in version 6.1.0 🎉
The release is available on:
v6.1.0Your semantic-release bot 📦🚀