diff --git a/balancer.go b/balancer.go index 9d943fba..44db9317 100644 --- a/balancer.go +++ b/balancer.go @@ -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() diff --git a/clientconn.go b/clientconn.go index 434cab43..41a52937 100644 --- a/clientconn.go +++ b/clientconn.go @@ -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 )