Skip to content

Skip failed read candidates in MasterReplicaConnectionProvider #3502 - #3975

Merged
a-TODO-rov merged 4 commits into
redis:mainfrom
gibkim:fix/3502-skip-failed-read-candidates
Oct 28, 2026
Merged

a-TODO-rov merged 4 commits into
redis:mainfrom
gibkim:fix/3502-skip-failed-read-candidates

Conversation

@gibkim

@gibkim gibkim commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

With ReadFrom selecting more than one node (e.g. REPLICA_PREFERRED), a read fails with RedisConnectionException as soon as one candidate cannot be connected, even when another candidate (often the master) is up. Fixes #3502.

Behavioral / Conceptual Changes

  • firstOpenInOrderOrFallback (order-sensitive ReadFrom) skips candidates whose connection future failed instead of propagating the first failure.
  • randomOpenOrFallback no longer fails through allOf when any candidate fails; it picks among the candidates that connected.
  • If no connected candidate is open, the fallback is the first candidate that connected. The read fails only if every candidate failed, with the failure of the first candidate.

This matches PooledClusterConnectionProvider.getReadConnection, which already keeps the successful candidates and errors only when all of them fail.

Testing

MasterReplicaConnectionProviderUnitTests: added tests for a failed replica with an order-sensitive and a random ReadFrom, for all candidates connecting, and for all candidates failing. Without the change, the two failed-replica tests fail.

Also checked with a static Master/Replica setup on local Redis nodes (MasterReplica.connect with a static node list, REPLICA_PREFERRED): 7.8.0 fails the read in 3 of 4 scenarios with replicas down (1 of 1 replica down; 1 of 2 replicas down, depending on which is tried first; 2 of 2 down), while the master is up. With this change, all of them succeed.

Make sure that:

  • You have read the contribution guidelines.
  • You have created a feature request first to discuss your contribution intent. Please reference the feature request ticket number in the pull request.
  • You applied code formatting rules using the mvn formatter:format target. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.

Note

Medium Risk
Changes connection-selection logic for multi-node ReadFrom reads in master/replica mode; improves resilience but alters when reads fail vs. fall back to another node.

Overview
Fixes master/replica read routing when ReadFrom yields multiple candidates (e.g. REPLICA_PREFERRED, ANY): a single unreachable replica no longer fails the read if another node connects.

Order-sensitive selection (firstOpenInOrderOrFallback) now treats failed connection futures as skippable via handle, and falls back to the first successfully connected candidate instead of blindly using connections.get(0). Random selection (randomOpenOrFallback) waits on settled futures so allOf is not aborted by one failure, filters to open connections among those that connected, and uses the same fallback. A new firstConnectedOrFailure helper centralizes “first success or propagate first failure when all fail,” aligning behavior with cluster pooled read selection.

Unit tests cover failed replica with order-sensitive and random ReadFrom, replica preference when all connect, and failure only when every candidate fails.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 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-28T08:38:43.777518Z 77e3e40 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.

@a-TODO-rov a-TODO-rov 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.

Looks good

@gibkim

gibkim commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

@a-TODO-rov Thanks for the review! I updated the branch since the earlier Redis 8.8 failure was in RediSearchStructuredKeyCodecSafetyIntegrationTests, which this change doesn't touch (the same test class also failed on #3963). Could you approve the workflow run when you get a chance?

@a-TODO-rov
a-TODO-rov merged commit de5c872 into redis:main Oct 28, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MasterReplica] ReadFrom.REPLICA_PREFERRED fails entirely when first replica is unreachable, even before Sentinel marks it +sdown

2 participants