Eliminate data race in ccBalancerWrapper (#1688)
This commit is contained in:
Родитель
1e1a47f0f2
Коммит
a62701e4aa
|
@ -98,6 +98,7 @@ type ccBalancerWrapper struct {
|
||||||
resolverUpdateCh chan *resolverUpdate
|
resolverUpdateCh chan *resolverUpdate
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
|
|
||||||
|
mu sync.RWMutex
|
||||||
subConns map[*acBalancerWrapper]struct{}
|
subConns map[*acBalancerWrapper]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,9 +143,11 @@ func (ccb *ccBalancerWrapper) watcher() {
|
||||||
select {
|
select {
|
||||||
case <-ccb.done:
|
case <-ccb.done:
|
||||||
ccb.balancer.Close()
|
ccb.balancer.Close()
|
||||||
|
ccb.mu.RLock()
|
||||||
for acbw := range ccb.subConns {
|
for acbw := range ccb.subConns {
|
||||||
ccb.cc.removeAddrConn(acbw.getAddrConn(), errConnDrain)
|
ccb.cc.removeAddrConn(acbw.getAddrConn(), errConnDrain)
|
||||||
}
|
}
|
||||||
|
ccb.mu.RUnlock()
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
@ -195,7 +198,9 @@ func (ccb *ccBalancerWrapper) NewSubConn(addrs []resolver.Address, opts balancer
|
||||||
acbw.ac.mu.Lock()
|
acbw.ac.mu.Lock()
|
||||||
ac.acbw = acbw
|
ac.acbw = acbw
|
||||||
acbw.ac.mu.Unlock()
|
acbw.ac.mu.Unlock()
|
||||||
|
ccb.mu.Lock()
|
||||||
ccb.subConns[acbw] = struct{}{}
|
ccb.subConns[acbw] = struct{}{}
|
||||||
|
ccb.mu.Unlock()
|
||||||
return acbw, nil
|
return acbw, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +209,9 @@ func (ccb *ccBalancerWrapper) RemoveSubConn(sc balancer.SubConn) {
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ccb.mu.Lock()
|
||||||
delete(ccb.subConns, acbw)
|
delete(ccb.subConns, acbw)
|
||||||
|
ccb.mu.Unlock()
|
||||||
ccb.cc.removeAddrConn(acbw.getAddrConn(), errConnDrain)
|
ccb.cc.removeAddrConn(acbw.getAddrConn(), errConnDrain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче