优化RPC调用

This commit is contained in:
GoEdgeLab
2020-11-15 11:58:08 +08:00
parent 332632ab9f
commit 22ce8bcef5
2 changed files with 19 additions and 8 deletions

View File

@@ -181,9 +181,14 @@ func (this *RPCClient) pickConn() *grpc.ClientConn {
// 检查连接状态
if len(this.conns) > 0 {
availableConns := []*grpc.ClientConn{}
for _, conn := range this.conns {
if conn.GetState() == connectivity.Ready {
availableConns = append(availableConns, conn)
for _, state := range []connectivity.State{connectivity.Ready, connectivity.Idle, connectivity.Connecting} {
for _, conn := range this.conns {
if conn.GetState() == state {
availableConns = append(availableConns, conn)
}
}
if len(availableConns) > 0 {
break
}
}