GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Refresh slot cache when slot connection acquisition fails by agarwalbharat · Pull Request #4544 · redis/jedis

Conversation

@agarwalbharat

@agarwalbharat agarwalbharat commented May 28, 2026 •
edited by cursor Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

getConnectionFromSlot() previously refreshed the cluster slot cache only when no pool was mapped for the requested slot. If a slot did have a mapped pool but borrowing a connection from that pool failed with a JedisConnectionException, the exception was propagated immediately.
This made getConnectionFromSlot() behave differently from normal command execution, where connection failures trigger retry handling and slot cache renewal.

Implemented the fallback in getConnectionFromSlot() for JedisConnectionException to renew the slot cache after a connection failure from the mapped slot pool, then resolve the slot again and retry connection acquisition. Preserve the existing fallback to a random reachable node when the slot is still unmapped after renewal.


Note

Medium Risk
Changes cluster slot connection selection used by command routing and direct slot APIs; behavior is more resilient but alters failure/retry timing during topology or node outages.

Overview
ClusterConnectionProvider.getConnectionFromSlot() now treats a failed borrow from the mapped slot pool like other cluster paths: on JedisConnectionException, it renews the slot cache, looks up the slot again, and retries (or falls back to a random reachable node if the slot is still unmapped). Renewal and retry logic live in a new getConnectionFromSlotAfterRenewing() helper, with the original connection failure attached as a suppressed exception when retries still fail.

A unit test (ClusterConnectionProviderTest) verifies cache renewal and a successful second borrow after a stale pool throws. The test class is added to the formatter plugin includes in pom.xml.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jit-ci

jit-ci Bot commented May 28, 2026

Copy link
Copy Markdown

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@agarwalbharat agarwalbharat mentioned this pull request May 28, 2026
Best way to "renewSlotCache" in JedisCluster? #4154
Closed
@ggivo
ggivo requested a review from Copilot May 28, 2026 12:38
Copilot started reviewing on behalf of ggivo May 28, 2026 12:38
View session
Copilot AI reviewed May 28, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Pull request overview

Makes getConnectionFromSlot() resilient to a stale slot→node mapping: if borrowing a connection from the mapped pool throws JedisConnectionException, the slot cache is now renewed and the lookup is retried (falling back to a random reachable node if the slot remains unmapped), matching the behavior of normal command-path retry handling. Logic shared between the previously-unmapped and newly-failing cases is extracted into a getConnectionFromSlotAfterRenewing helper, with the original exception attached as suppressed when a follow-up attempt also fails.

Changes:

  • Extract slot-cache renewal + retry logic into getConnectionFromSlotAfterRenewing, preserving the original exception via addSuppressed.
  • Wrap the initial connectionPool.getResource() call in getConnectionFromSlot with a JedisConnectionException catch that invokes the renewal helper.
  • Add a unit test verifying that a failing first getResource() triggers renewClusterSlots and a successful connection from the refreshed pool.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/main/java/redis/clients/jedis/providers/ClusterConnectionProvider.java Adds renewal-and-retry fallback on JedisConnectionException in getConnectionFromSlot; refactors shared logic into helper.
src/test/java/redis/clients/jedis/providers/ClusterConnectionProviderTest.java New unit test validating renewal and retry behavior when the mapped slot pool fails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/redis/clients/jedis/providers/ClusterConnectionProvider.java Outdated
Comment on lines +218 to +220
try{
return connectionPool.getResource();
} else {
// no choice, fallback to new connection to random node
return getConnection();
}catch(JedisConnectionException e){
@agarwalbharat
agarwalbharat force-pushed the fix/refresh-slot-cache-on-slot-connection-failure branch from 3f0819f to 36eb38b Compare May 28, 2026 13:22
@ggivo
ggivo self-requested a review May 28, 2026 13:40
@agarwalbharat
agarwalbharat force-pushed the fix/refresh-slot-cache-on-slot-connection-failure branch from 36eb38b to 628b7fd Compare May 28, 2026 13:45
@ggivo

ggivo commented May 28, 2026

Copy link
Copy Markdown
Collaborator

@agarwalbharat
Thanks for spending time on this issue! As far as I see, this PR addresses #4154.

To get the Java Format Check green, the newly added test file needs to be opted into the formatter. Please add it to the <includes> block of the formatter-maven-plugin configuration in
pom.xml (https://github.com/redis/jedis/blob/master/pom.xml#L527):

<include>src/test/java/redis/clients/jedis/providers/ClusterConnectionProviderTest.java</include>
then to auto format it you can use
mvn formatter:format.

I'll do a closer review pass shortly — thanks again!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ggivo ggivo added the status: waiting-for-review label May 28, 2026
@agarwalbharat
Refresh slot cache when slot connection acquisition fails
32fcf36
Implemented the fallback in getConnectionFromSlot()

Update getConnectionFromSlot() to renew the slot cache after a connection failure from the mapped slot pool, then resolve the slot again and retry connection acquisition. Preserve the existing fallback to a random reachable node when the slot is still unmapped after renewal.
@agarwalbharat
agarwalbharat force-pushed the fix/refresh-slot-cache-on-slot-connection-failure branch from 628b7fd to 32fcf36 Compare May 28, 2026 13:58
@agarwalbharat

agarwalbharat commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

To get the Java Format Check green, the newly added test file needs to be opted into the formatter. Please add it to the <includes> block of the formatter-maven-plugin configuration in

Thank you for the suggestion. I’ve added the file to the formatter includes and applied the formatting changes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ggivo

ggivo commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Not merging this PR — superseded by #4555. Recording the rationale here for traceability.

Why we're not taking this approach:
getConnectionFromSlot() is reached via the command path (doExecuteCommand → resolver.resolve → getConnection(args) → getConnectionFromSlot). ClusterCommandExecutor.handleConnectionProblem deliberately throttles renewal — only after 2 consecutive failures + backoff — specifically to avoid renewal storms.

This PR makes the first failed getResource() trigger renewSlotCache() immediately, with no backoff and no gate. JedisClusterInfoCache.renewClusterSlots() relies on rediscoverLock.tryLock(), which dedups concurrent renewals but not serial ones — so under concurrency a brief network hiccup can fan out into back-to-back renewals on the command path.

Agreed direction (see issue discussion :

  1. Short term — expose a manual renewSlotCache() for direct getConnectionFromSlot() callers (which bypass ClusterCommandExecutor and so don't get handleConnectionProblem today). Expose renewSlotCache on JedisCluster as public API #4555
  2. Longer term — redesign topology refresh per the TODO at ClusterCommandExecutor.java:338: per-node success/failure tracking with a configurable grace period. Tracked separately as its own effort.

Thanks @agarwalbharat for the analysis that led here — closing this in favor of #4555. Will follow up on the topology-refresh redesign in a dedicated issue.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ggivo ggivo removed the status: waiting-for-review label Jun 3, 2026
@ggivo ggivo closed this Jun 3, 2026
@ggivo ggivo mentioned this pull request Jun 3, 2026
Cluster topology refresh improvements: unified refresh policy #4556
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@ggivo ggivo Awaiting requested review from ggivo

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@agarwalbharat @ggivo
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.