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

This commit is contained in:
Alec Thomas 2017-05-06 06:59:00 +10:00 коммит произвёл dfawley
Родитель 2eb11e102d
Коммит ffa4ec7da2
2 изменённых файлов: 5 добавлений и 0 удалений

Просмотреть файл

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

Просмотреть файл

@ -78,6 +78,8 @@ var (
errConnClosing = errors.New("grpc: the connection is closing")
// errConnUnavailable indicates that 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
minConnectTimeout = 20 * time.Second
)