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.
This commit is contained in:
Vladimir Mihailenco 2020-12-06 10:03:33 +02:00 committed by GitHub
commit a60ca8bc24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -177,11 +177,13 @@ func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
opt.init()
connPool := newConnPool(opt)
failover.mu.Lock()
failover.onFailover = func(ctx context.Context, addr string) {
_ = connPool.Filter(func(cn *pool.Conn) bool {
return cn.RemoteAddr().String() != addr
})
}
failover.mu.Unlock()
c := Client{
baseClient: newBaseClient(opt, connPool),