Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to Close Sentinel when the NewFailoverClusterClient is Closed. #2968

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions osscluster.go
Expand Up @@ -62,6 +62,8 @@ type ClusterOptions struct {

OnConnect func(ctx context.Context, cn *Conn) error

OnClose func() error

Protocol int
Username string
Password string
Expand Down Expand Up @@ -868,7 +870,6 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient {
c.state = newClusterStateHolder(c.loadState)
c.cmdsInfoCache = newCmdsInfoCache(c.cmdsInfo)
c.cmdable = c.Process

c.initHooks(hooks{
dial: nil,
process: c.process,
Expand All @@ -895,7 +896,11 @@ func (c *ClusterClient) ReloadState(ctx context.Context) {
// It is rare to Close a ClusterClient, as the ClusterClient is meant
// to be long-lived and shared between many goroutines.
func (c *ClusterClient) Close() error {
return c.nodes.Close()
err := c.nodes.Close()
if c.opt.OnClose != nil && err == nil {
err = c.opt.OnClose()
}
return err
}

// Do create a Cmd from the args and processes the cmd.
Expand Down
2 changes: 1 addition & 1 deletion sentinel.go
Expand Up @@ -825,7 +825,7 @@ func NewFailoverClusterClient(failoverOpt *FailoverOptions) *ClusterClient {
}
return slots, nil
}

opt.OnClose = failover.Close
c := NewClusterClient(opt)

failover.mu.Lock()
Expand Down