Browse Source

clientv3: fix balancer update address bug

fanmin shi 9 years ago
parent
commit
0c4e67c1f4
1 changed files with 6 additions and 2 deletions
  1. 6 2
      clientv3/balancer.go

+ 6 - 2
clientv3/balancer.go

@@ -124,7 +124,11 @@ func (b *simpleBalancer) updateAddrs(eps []string) {
 		addrs = append(addrs, grpc.Address{Addr: getHost(eps[i])})
 		addrs = append(addrs, grpc.Address{Addr: getHost(eps[i])})
 	}
 	}
 	b.addrs = addrs
 	b.addrs = addrs
-	b.notifyCh <- addrs
+	// updating notifyCh can trigger new connections,
+	// but balancer only expects new connections if all connections are down
+	if b.pinAddr == "" {
+		b.notifyCh <- addrs
+	}
 }
 }
 
 
 func (b *simpleBalancer) Up(addr grpc.Address) func(error) {
 func (b *simpleBalancer) Up(addr grpc.Address) func(error) {
@@ -220,7 +224,7 @@ func (b *simpleBalancer) Close() error {
 	close(b.notifyCh)
 	close(b.notifyCh)
 	b.pinAddr = ""
 	b.pinAddr = ""
 
 
-	// In the case of follwing scenerio:
+	// In the case of following scenario:
 	//	1. upc is not closed; no pinned address
 	//	1. upc is not closed; no pinned address
 	// 	2. client issues an rpc, calling invoke(), which calls Get(), enters for loop, blocks
 	// 	2. client issues an rpc, calling invoke(), which calls Get(), enters for loop, blocks
 	// 	3. clientconn.Close() calls balancer.Close(); closed = true
 	// 	3. clientconn.Close() calls balancer.Close(); closed = true