Skip to content

Commit

Permalink
clientv3: handle stale endpoint in health balancer
Browse files Browse the repository at this point in the history
Signed-off-by: Gyu-Ho Lee <[email protected]>
  • Loading branch information
gyuho committed Oct 19, 2017
1 parent a8f9de2 commit ad24700
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions clientv3/health_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ func (hb *healthBalancer) updateUnhealthy(timeout time.Duration) {
case <-time.After(timeout):
hb.mu.Lock()
for k, v := range hb.unhealthy {
if _, ok := hb.host2ep[k]; !ok {
delete(hb.unhealthy, k)
if logger.V(4) {
logger.Infof("clientv3/health-balancer: removes stale host:port %q from unhealthy", k)
}
continue
}
if time.Since(v) > timeout {
delete(hb.unhealthy, k)
if logger.V(4) {
Expand Down Expand Up @@ -189,6 +196,10 @@ func (hb *healthBalancer) endpointError(addr string, err error) {

func (hb *healthBalancer) mayPin(addr grpc.Address) bool {
hb.mu.RLock()
if _, ok := hb.host2ep[addr.Addr]; !ok { // stale endpoint
hb.mu.RUnlock()
return false
}
skip := len(hb.addrs) == 1 || len(hb.unhealthy) == 0 || len(hb.addrs) == len(hb.unhealthy)
failedTime, bad := hb.unhealthy[addr.Addr]
dur := hb.healthCheckTimeout
Expand Down

0 comments on commit ad24700

Please sign in to comment.