Skip to content

Commit a60ca8b

Browse files
authored
Merge pull request #1564 from git-hulk/fix/data-race-in-sentinel-client
FIX: data race warning in sentinel client since the newConnPool would spawn the new goroutine and use the onFailover at the same time.
2 parents 0b9986c + 956f43e commit a60ca8b

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)