Skip to content

Commit 43d9b98

Browse files
committed
Fix race
1 parent a60ca8b commit 43d9b98

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

sentinel.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
177177
opt.init()
178178

179179
connPool := newConnPool(opt)
180+
180181
failover.mu.Lock()
181182
failover.onFailover = func(ctx context.Context, addr string) {
182183
_ = connPool.Filter(func(cn *pool.Conn) bool {
@@ -648,6 +649,7 @@ func (c *sentinelFailover) discoverSentinels(ctx context.Context) {
648649

649650
func (c *sentinelFailover) listen(pubsub *PubSub) {
650651
ctx := context.TODO()
652+
651653
if c.onUpdate != nil {
652654
c.onUpdate(ctx)
653655
}
@@ -725,9 +727,12 @@ func NewFailoverClusterClient(failoverOpt *FailoverOptions) *ClusterClient {
725727
}
726728

727729
c := NewClusterClient(opt)
730+
731+
failover.mu.Lock()
728732
failover.onUpdate = func(ctx context.Context) {
729733
c.ReloadState(ctx)
730734
}
735+
failover.mu.Unlock()
731736

732737
return c
733738
}

0 commit comments

Comments
 (0)