Skip to content

register onClose hook in FailoverClusterClient - #4000

Open
roganartu wants to merge 3 commits into
redis:masterfrom
roganartu:fix-leak
Open

roganartu wants to merge 3 commits into
redis:masterfrom
roganartu:fix-leak

Conversation

@roganartu

@roganartu roganartu commented Aug 29, 2026 •

Copy link
Copy Markdown

Fixes #3999


Note

Low Risk
Lifecycle-only change that mirrors existing FailoverClient close behavior; low risk aside from hook ordering interacting with other cluster onClose registrations.

Overview
Fixes sentinel resource cleanup when closing a failover cluster client (#3999).

ClusterClient now owns an onClose hook registry (initialized in NewClusterClient) and Close() runs registered hooks after autopipeliners and node pools shut down.

NewFailoverClusterClient registers failover.Close on that registry—the same pattern as NewFailoverClient—so closing the cluster client tears down the Sentinel client and failover pub/sub instead of leaving them running.

Reviewed by Cursor Bugbot for commit e33a937. 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: 4ef24b822d

ℹ️ 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 osscluster.go
Comment on lines +1479 to +1481
if err := c.onClose.run(); err != nil && firstErr == nil {
firstErr = err
}

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 Make Sentinel closure terminal during cluster shutdown

When a failover-cluster topology reload overlaps Close, this hook can close the current Sentinel and then have it immediately recreated: clusterStateHolder.LazyReload goroutines are not stopped by ClusterClient.Close, and their ClusterSlots callback calls sentinelFailover.MasterAddr/replicaAddrs, which create a new Sentinel whenever c.sentinel is nil because sentinelFailover has no closed state. The listener itself schedules an initial reload, so closing shortly after first use can hit this race; the reopened Sentinel's PubSub goroutine and connections then outlive the closed client. Shutdown needs to make Sentinel closure terminal or cancel/wait for reloads before running this hook.

Useful? React with 👍 / 👎.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 4ef24b8. Configure here.

Comment thread osscluster.go
}
if err := c.onClose.run(); err != nil && firstErr == nil {
firstErr = err
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sentinel can restart after Close

Medium Severity

ClusterClient.Close runs the Sentinel hook after nodes.Close, unlike FailoverClient, so listen can still call ReloadState during teardown. A concurrent LazyReload can then invoke ClusterSlots after failover.Close, and MasterAddr reconnects and starts a new listen goroutine that is never shut down.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4ef24b8. Configure here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cc @roganartu please check this one.

@ndyakov ndyakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @roganartu, this looks good.

@ndyakov
ndyakov self-requested a review September 2, 2026 14:57
@ndyakov

ndyakov commented Oct 2, 2026

Copy link
Copy Markdown
Member

@roganartu would you be able to check the bot review, thank you.

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.

FailoverClusterClient leaks Sentinel connections

2 participants