valkey-go icon indicating copy to clipboard operation
valkey-go copied to clipboard

feat: Add MaxMovedRedirections option to prevent infinite redirect loops

Open nirchetrit opened this issue 1 month ago • 1 comments

Description

This PR introduces a new ClusterOption called MaxMovedRedirections. This option allows users to configure a maximum limit for MOVED redirections during cluster operations.

Previously, the client could potentially enter an infinite loop of redirects if the cluster was misconfigured or unstable. This change ensures the client fails fast with a specific error (ErrMaxMovedRedirectionsExceeded) once the configured redirection limit is reached.

Changes

  • New Option: Added MaxMovedRedirections to ClusterOption.
  • New Error: Introduced ErrMaxMovedRedirectionsExceeded to signal when the redirection limit is hit.
  • Logic Update: Updated the retry loops in cluster.go (including DoMulti and pipelines) to respect this limit.
  • Error Handling: Enhanced error inspection to ensure we only count actual MOVED responses against this limit, preserving other errors (like network issues) where appropriate.

Motivation

To allow the client to fail faster with a specific error in case of a moved redirection loop during cluster rebalance/topology changes.

nirchetrit avatar Nov 26 '25 13:11 nirchetrit

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 95.20%. Comparing base (262cdd2) to head (81e6fa4). :warning: Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #92      +/-   ##
==========================================
+ Coverage   94.63%   95.20%   +0.56%     
==========================================
  Files          99       99              
  Lines       46335    44081    -2254     
==========================================
- Hits        43851    41968    -1883     
+ Misses       2095     1726     -369     
+ Partials      389      387       -2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov-commenter avatar Nov 27 '25 23:11 codecov-commenter

Thank you @nirchetrit!

rueian avatar Dec 03 '25 06:12 rueian