Skip to content

autopipelining: commands fail during cluster topology changes due to pipeline-level MOVED handling #2075

Closed

Description

@ivoronin

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:

  1. Autopipelining groups commands for slots 100 and 200 together (both served by Node A at the time of batching)
  2. The pipeline sends everything to Node A
  3. 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

  1. self-assigned this
    on Feb 9, 2026
  2. PavelPashov commented on Feb 9, 2026

    @PavelPashov
    Contributor

    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?

  3. ivoronin commented on Feb 9, 2026

    @ivoronin
    ContributorAuthor

    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.

  4. PavelPashov commented on Sep 15, 2026

    @PavelPashov
    Contributor

    @Bubblegunn Thank you for the reproduction and investigation! Yes, a contribution preserving node-based batching and handling MOVED commands 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?

  5. PavelPashov commented on Sep 24, 2026

    @PavelPashov
    Contributor

    @Bubblegunn thanks for the detailed proposal and the correction. Keeping node-based batching and retrying only the commands that return MOVED, ASK, or TRYAGAIN sounds 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:

    • Keep successful results and unrelated errors unchanged, preserve result order, and wait for all retries before completing the pipeline. Later failures shouldn't cause successful commands to run again.
    • Keep each command's remaining retry budget and delays across attempts, including the first retry. A limit of zero should mean no resend, and one should allow one resend.
    • For ASK, send ASKING and the command directly to the requested node without changing slot ownership.
    • Keep transaction behavior, replica reads, and the existing safeguards for CLUSTERDOWN and 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?

  6. PavelPashov commented on Sep 30, 2026

    @PavelPashov
    Contributor

    @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/EXEC where 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.

  7. added a commit that references this issue on Oct 20, 2026
    46b3191
  8. added a commit that references this issue on Nov 23, 2026
  9. github-actions commented on Nov 23, 2026

    @github-actions

    🎉 This issue has been resolved in version 6.1.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions