feat: Add MaxMovedRedirections option to prevent infinite redirect loops
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
MaxMovedRedirectionstoClusterOption. -
New Error: Introduced
ErrMaxMovedRedirectionsExceededto signal when the redirection limit is hit. -
Logic Update: Updated the retry loops in
cluster.go(includingDoMultiand pipelines) to respect this limit. -
Error Handling: Enhanced error inspection to ensure we only count actual
MOVEDresponses 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.
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.
Thank you @nirchetrit!