Skip to content

feat(client): add MaxCommandRedirectionsError for cluster redirections - #3386

Open
Piyush0049 wants to merge 2 commits into
redis:masterfrom
Piyush0049:feat/max-command-redirections-error
Open

feat(client): add MaxCommandRedirectionsError for cluster redirections#3386
Piyush0049 wants to merge 2 commits into
redis:masterfrom
Piyush0049:feat/max-command-redirections-error

Conversation

@Piyush0049

@Piyush0049 Piyush0049 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Description

This pull request resolves a // TODO: error class comment by adding a new MaxCommandRedirectionsError.

Previously, when a cluster command exceeded the maximum number of allowed redirections (e.g., getting stuck in a MOVED or ASK loop), the client simply re-threw the last received raw Redis error. This obscured the actual cause of the failure from the developer.

The new error class wraps the original error, making it clear that a redirection limit was hit, thereby improving debugging and observability for cluster topology issues.

Updates in this PR:

  • Added MaxCommandRedirectionsError to wrap the raw routing errors.
  • Fixed a minor logic flaw so that non-Error objects are properly re-thrown instead of being accidentally wrapped.
  • Added a full test suite case using testUtils.testWithCluster that intentionally creates a MOVED loop to verify the MaxCommandRedirectionsError is correctly thrown.

Checklist

  • Does npm test pass with this change (including linting)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

Note

Low Risk
Localized cluster error-handling change with clearer failure mode; behavior only differs when the redirection cap is exceeded on redirect errors.

Overview
When cluster command routing or sharded sSubscribe hits maxCommandRedirections while still getting ASK/MOVED replies, the client now throws MaxCommandRedirectionsError (Too many Cluster redirections) with the last redirect as cause, instead of surfacing only the raw Redis error.

The _execute redirect loop rethrows non-Error values immediately, publishes tracing on limit exhaustion, and applies the new error for redirect loops; SSUBSCRIBE uses the same limit behavior for MOVED. Integration tests deliberately create a MOVED loop (low maxCommandRedirections) for get and sSubscribe.

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

@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: b694fe1e61

ℹ️ 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 packages/client/lib/cluster/index.ts Outdated
Comment thread packages/client/lib/cluster/index.ts Outdated
@Piyush0049
Piyush0049 force-pushed the feat/max-command-redirections-error branch from b694fe1 to 303eebd Compare August 1, 2026 19:11

@nkaradzhov nkaradzhov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Piyush0049 ,

he test only covers _execute (cluster.get); the SSUBSCRIBE path is untested — please add a case or note why it's omitted.

@Piyush0049

Copy link
Copy Markdown
Contributor Author

@nkaradzhov I have pushed a commit adding a case. Please do let me know if it is appropriate or not.

@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: 6666d7a2ba

ℹ️ 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".

}
}, {
serverArguments: [],
numberOfMasters: 2,

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 Gate sharded Pub/Sub test on Redis 7

When the suite is run with a Redis 6 test image (for example via the configurable --redis-tag/--redis-version test options), testWithCluster only skips tests that set minimumDockerVersion, and SSUBSCRIBE is not available before Redis 7. The other sharded Pub/Sub cases in this file are gated with [7]; without the same gate here, this new test runs on Redis 6 and rejects with an unknown-command error instead of MaxCommandRedirectionsError, breaking versioned test runs. Add minimumDockerVersion: [7] to this options block.

Useful? React with 👍 / 👎.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants