Skip to content

Do not throw when auto-pipelining meets a slot the cluster does not own - #2233

Merged
PavelPashov merged 4 commits into
redis:mainfrom
PerryLink:fix/autopipelining-missing-slot
Oct 19, 2026
Merged

PavelPashov merged 4 commits into
redis:mainfrom
PerryLink:fix/autopipelining-missing-slot

Conversation

@PerryLink

@PerryLink PerryLink commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What

With Cluster + enableAutoPipelining, a command whose slot is not in the cached CLUSTER SLOTS
map throws synchronously, before a Promise exists, so await and .catch() cannot see it:

// lib/autoPipelining.ts, executeWithAutoPipelining
client.slots[slot].join(',')     // slot not present -> TypeError: Cannot read properties of undefined

A missing slot is a normal state rather than a corrupt one: CLUSTER SLOTS only lists the slots the
cluster actually owns (an unassigned slot can coexist with cluster_state:ok when
cluster-require-full-coverage no), and the map is incomplete while topology is being discovered.

The non-auto-pipelined path already handles this: lib/cluster/index.ts:842-848 falls back to a
random node when the slot is unknown. Auto-pipelining is the only place that does not.

The change

When the slot is missing, fall back to the bucket's existing generic key ("main"), so the commands
are sent through the normal routing and the server or the existing redirection logic decides, instead
of a client-side TypeError. One guard, no new retry policy.

Adds one functional test: a cluster whose CLUSTER SLOTS omits the target slot, asserting the call
rejects with a normal Redis error rather than throwing synchronously.

Verification

  • before: TypeError ... reading 'join' at lib/autoPipelining.ts:187, exit 1;
  • after: the same test node passes; the whole file is 25 passing;
  • tsc --noEmit, eslint ./lib (0 errors) and prettier --check all exit 0;
  • git apply --check against a pristine main succeeds.

The test uses fixed port 30007, matching the file's existing style, and still needs a Docker Redis in
CI for the full functional suite.

No CLA/DCO in .github/CONTRIBUTING.md; this is the "small, isolated fix with a focused test" case it
explicitly allows to go straight to a PR.


Note

Medium Risk
Touches cluster command routing and auto-pipeline bucketing for edge-case topologies; behavior change is narrow but affects how concurrent commands to unassigned slots are grouped and sent.

Overview
Cluster auto-pipelining no longer crashes when a key’s hash slot is missing from the cached CLUSTER SLOTS map. executeWithAutoPipelining now checks client.slots[slot] before building the pipeline bucket key; mapped slots still bucket by node list, while unmapped slots get a per-slot key (#slot:${slot}) so they are not merged into one pipeline (which would wrongly route multiple unknown slots through the first key’s node).

Adds a functional test with a partial slot table (key above slot 8191) and a unit test that two keys in empty slot entries create two auto-pipeline buckets.

Reviewed by Cursor Bugbot for commit de68a8f. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T08:03:27.399809Z de68a8f New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb67b6256a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/autoPipelining.ts Outdated
// routed like a non-pipelined command and the server's cluster error
// handling applies, instead of throwing on an undefined entry.
const nodeKeys = client.slots[slot];
slotKey = nodeKeys ? nodeKeys.join(",") : "main";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep uncached slots in separate pipeline buckets

When commands for two different uncached slots are issued in the same event-loop turn, this puts both into main. Pipeline.generateMultiWithNodes then treats their two undefined _groupsBySlot entries as one allocation group and sends both to one sampled node; if the slots are actually owned by different nodes during topology discovery, the replies can be different MOVED errors, so Pipeline.fillResult cannot apply its common-error redirect retry and both calls fail instead of following normal cluster routing. Use a per-slot fallback bucket so unrelated unknown slots are not merged.

AGENTS.md reference: AGENTS.md:L92-L94

Useful? React with 👍 / 👎.

Two commands hashing to slots without a node group shared the generic bucket,
so Pipeline compared their two empty allocation groups as equal and sent both
to the first key's node; the second one then failed with a bare MOVED that the
pipeline could not follow. Bucket by slot instead, and cover it with a test.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a321f65e8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/autoPipelining.ts Outdated
// Pipeline reads their two empty allocation groups as one group, sending
// both to the first key's node.
const nodeKeys = client.slots[slot];
slotKey = nodeKeys ? nodeKeys.join(",") : `slot:${slot}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep fallback bucket keys disjoint from node keys

When a cluster advertises hostname slot on port 6379 while hash slot 6379 is absent from the cache, this fallback string is identical to the normal bucket key produced by nodeKeys.join(",") for that node. A command for the missing slot issued in the same event-loop turn as a command for any slot owned by that node is therefore placed in one pipeline; Pipeline.generateMultiWithNodes sees different allocation groups and rejects the entire pipeline, so the otherwise routable known-slot command fails too. Use a fallback namespace that cannot overlap node keys (or a distinct key type).

AGENTS.md reference: AGENTS.md:L92-L94

Useful? React with 👍 / 👎.

@PerryLink

Copy link
Copy Markdown
Contributor Author

Pushed 4a321f6 for the finding above. Two commands hashing to slots with no node group were sharing the generic main bucket; Pipeline reads their two empty allocation groups as equal and sends both to the first key's node, where the second one comes back as a bare MOVED the pipeline cannot follow. The fallback bucket is per-slot now (slot:<n>), so unrelated unknown slots never share a pipeline. test/unit/autoPipelining.ts covers it: the new test is red on the previous commit (expected [ 'main:read' ] to have a length of 2 but got 1) and green after it, 4 passing.

The fallback bucket was `slot:<n>`, which a node key can equal: node keys are
`host:port` pairs, so a node advertised as host `slot` on port 6379 produces the
same string for a missing hash slot 6379 and Pipeline then rejects the whole batch.
Prefix the fallback with `#`, which cannot occur in a node key.
@PerryLink

Copy link
Copy Markdown
Contributor Author

Good catch — pushed 465d16b. The fallback bucket is now #slot:<n>: node keys are always host:port lists, and # cannot occur in one, so the fallback can no longer equal a real node key. (The test still covers the separation: two uncached slots stay in two pipelines, 4 passing; tsc clean.)

@PavelPashov PavelPashov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for the contribution

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@PavelPashov
PavelPashov merged commit e04bb49 into redis:main Oct 19, 2026
22 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 23, 2026
# [6.1.0](v6.0.0...v6.1.0) (2026-11-23)

### Bug Fixes

* accept field arrays in hmget/hmgetBuffer types ([#2167](#2167)) ([c0cd66c](c0cd66c))
* align auto-pipeline callbacks for dynamic commands ([#2180](#2180)) ([7479cab](7479cab))
* apply the legacy reply shape to uppercase command names ([#2252](#2252)) ([8ecb423](8ecb423))
* clean up Sentinel failover subscriptions after quit ([#2198](#2198)) ([727edfa](727edfa))
* close the monitor connection when monitor() rejects ([#2247](#2247)) ([3cfe93f](3cfe93f))
* cluster stuck in close ([#2217](#2217)) ([a5fad1d](a5fad1d))
* **cluster:** bucket autopipelined MSET objects by their first key ([#2207](#2207)) ([b4e3237](b4e3237))
* **cluster:** do not reject pipeline commands for connecting nodes when offline queue is disabled ([#2277](#2277)) ([71516ca](71516ca)), closes [#2096](#2096) [Cluster#sendCommand](https://github.com/Cluster/issues/sendCommand) [#2276](#2276)
* **cluster:** do not throw when auto-pipelining meets an uncached slot ([#2233](#2233)) ([e04bb49](e04bb49))
* **cluster:** don't fall back to a replica when no primary is left ([#2275](#2275)) ([c353e34](c353e34))
* **cluster:** emit sharded subscriber connect errors silently ([#2241](#2241)) ([00c9a22](00c9a22))
* **cluster:** end when quit() or disconnect() is called while reconnecting ([#2240](#2240)) ([8526785](8526785))
* **cluster:** hash autopipelined Buffer keys by their bytes ([#2208](#2208)) ([a8378bd](a8378bd)), closes [Command#getSlot](https://github.com/Command/issues/getSlot)
* **cluster:** hash lone surrogates as the UTF-8 Node sends ([#2242](#2242)) ([cfa464d](cfa464d))
* **cluster:** keep forwarding sharded messages after reconnecting from end ([#2251](#2251)) ([326e987](326e987))
* **cluster:** map every slot when stringNumbers is enabled ([#2255](#2255)) ([8ce4115](8ce4115))
* **cluster:** match Buffer shard channels when unsubscribing ([#2203](#2203)) ([d997d01](d997d01))
* **cluster:** pass the retry delay to the reconnecting event ([#2291](#2291)) ([ed50383](ed50383))
* **cluster:** resend only the redirected command in a pipeline ([#2214](#2214)) ([46b3191](46b3191)), closes [#2075](#2075) [Pipeline#exec](https://github.com/Pipeline/issues/exec) [Cluster#sendCommand](https://github.com/Cluster/issues/sendCommand) [Pipeline#exec](https://github.com/Pipeline/issues/exec) [Cluster#sendCommand](https://github.com/Cluster/issues/sendCommand) [Pipeline#exec](https://github.com/Pipeline/issues/exec)
* **cluster:** stay ended when nodes removed by disconnect() end late ([#2237](#2237)) ([61896e5](61896e5)), closes [#2217](#2217)
* **cluster:** stop refreshing slots when disconnect() is called during a refresh ([#2249](#2249)) ([80501ed](80501ed))
* **cluster:** support zero-argument sunsubscribe with sharded subscribers ([#2137](#2137)) ([13ff050](13ff050)), closes [#2133](#2133)
* **cluster:** vendor cluster-key-slot to fix empty hash tag slot bug ([#2172](#2172)) ([b479b76](b479b76))
* correct Sentinel retry ordering after node connection failures ([#2246](#2246)) ([a10e0fa](a10e0fa))
* decode integer replies up to MAX_SAFE_INTEGER exactly ([#2164](#2164)) ([28940b5](28940b5))
* decode RESP3 attribute replies instead of failing the connection ([#2213](#2213)) ([6a8cb3e](6a8cb3e)), closes [#decodeNestedType](https://github.com/redis/ioredis/issues/decodeNestedType) [#decodeMapAsObject](https://github.com/redis/ioredis/issues/decodeMapAsObject) [#decodeMapKey](https://github.com/redis/ioredis/issues/decodeMapKey)
* decode RESP3 doubles with Number ([#2150](#2150)) ([6fb5a10](6fb5a10))
* end when quit() or disconnect() is called while reconnecting ([#2245](#2245)) ([81bc16a](81bc16a))
* handle rejection from the db-restoring select on reconnectOnError ([#2229](#2229)) ([1b744ca](1b744ca))
* handle rejections from auto-resubscribe and select on reconnect ([#2187](#2187)) ([de2fbdf](de2fbdf))
* inherit connectTimeout for cluster subscribers ([#2220](#2220)) ([db57c2d](db57c2d))
* keep String.prototype in fast mode after defining VerbatimString ([#2206](#2206)) ([90e1261](90e1261))
* keep subscriber mode while other channel kinds remain subscribed ([#2196](#2196)) ([eb97beb](eb97beb))
* keep the exec error out of its own previousErrors ([#2218](#2218)) ([2c602cf](2c602cf))
* keep the selected db for commands queued while reconnecting ([#2235](#2235)) ([9f90154](9f90154))
* preserve empty keys and match patterns in scan streams ([#2199](#2199)) ([b169c3a](b169c3a))
* redact credentials from the command attached to errors ([#2231](#2231)) ([a26f8de](a26f8de)), closes [#1713](#1713)
* reject unfulfilled commands dropped on reconnect ([#2194](#2194)) ([d95d05a](d95d05a)), closes [#2193](#2193)
* reset retry attempts when connect() is called after giving up ([#2204](#2204)) ([b597303](b597303)), closes [#1463](#1463)
* reset the manual close state when connect() is called after end ([#2250](#2250)) ([7713c4b](7713c4b))
* resolve argument-less (p)unsubscribe once its own kind is empty ([#2238](#2238)) ([280812b](280812b))
* restore the db selected by a non-lowercase SELECT after reconnecting ([#2248](#2248)) ([400b774](400b774))
* **sentinel:** handle errors on failover detector connections ([#2257](#2257)) ([09bcda5](09bcda5))
* **sentinel:** retry unreachable sentinels in a loop instead of recursing ([#2270](#2270)) ([6bee8d2](6bee8d2))
* **types:** accept documented TLS profile options ([#2195](#2195)) ([56a7fb8](56a7fb8)), closes [#1626](#1626)
* **types:** add event overloads to Cluster interface ([#2201](#2201)) ([3996eaf](3996eaf)), closes [#2191](#2191)
* **types:** add smessage and smessageBuffer event overloads ([#2191](#2191)) ([ee48f4c](ee48f4c)), closes [#2190](#2190)
* **types:** allow number for zrange stop argument ([#2163](#2163)) ([932f4c2](932f4c2))

### Features

* add BITRANGEINTARRAY command ([#2279](#2279)) ([b141399](b141399))
* add set member expiration commands ([#2261](#2261)) ([5efba6b](5efba6b)), closes [redis/redis#15938](redis/redis#15938)
* bless commands ([#2209](#2209)) ([9181ee0](9181ee0))
* **cluster:** allow configuring node role for Pub/Sub subscriber ([#2176](#2176)) ([6b9130c](6b9130c))
* sharded subscriber health check ([#2268](#2268)) ([1b25ffb](1b25ffb))
* smart client handoffs ([#2165](#2165)) ([d8ae3cb](d8ae3cb))
* sorted set move commands ([#2288](#2288)) ([2f4f09d](2f4f09d))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included 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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants