Ensure that RoundRobin.Close() does not panic. (#1139)

This commit is contained in:
Alec Thomas 2017-05-06 06:59:00 +10:00 committed by dfawley
parent 2eb11e102d
commit ffa4ec7da2
2 changed files with 5 additions and 0 deletions

View File

@ -385,6 +385,9 @@ func (rr *roundRobin) Notify() <-chan []Address {
func (rr *roundRobin) Close() error { func (rr *roundRobin) Close() error {
rr.mu.Lock() rr.mu.Lock()
defer rr.mu.Unlock() defer rr.mu.Unlock()
if rr.done {
return errBalancerClosed
}
rr.done = true rr.done = true
if rr.w != nil { if rr.w != nil {
rr.w.Close() rr.w.Close()

View File

@ -78,6 +78,8 @@ var (
errConnClosing = errors.New("grpc: the connection is closing") errConnClosing = errors.New("grpc: the connection is closing")
// errConnUnavailable indicates that the connection is unavailable. // errConnUnavailable indicates that the connection is unavailable.
errConnUnavailable = errors.New("grpc: the connection is unavailable") errConnUnavailable = errors.New("grpc: the connection is unavailable")
// errBalancerClosed indicates that the balancer is closed.
errBalancerClosed = errors.New("grpc: balancer is closed")
// minimum time to give a connection to complete // minimum time to give a connection to complete
minConnectTimeout = 20 * time.Second minConnectTimeout = 20 * time.Second
) )