Skip to content

Commit 956f43e

Browse files
committed
FIX: data race warning in sentinel client since the newConnPool would spawn the new
goroutine and use the onFailover at the same time.
1 parent 5aedb90 commit 956f43e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

sentinel.go

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

179179
connPool := newConnPool(opt)
180+
failover.mu.Lock()
180181
failover.onFailover = func(ctx context.Context, addr string) {
181182
_ = connPool.Filter(func(cn *pool.Conn) bool {
182183
return cn.RemoteAddr().String() != addr
183184
})
184185
}
186+
failover.mu.Unlock()
185187

186188
c := Client{
187189
baseClient: newBaseClient(opt, connPool),

0 commit comments

Comments
 (0)