ソースを参照

clientv3: use Endpoints[0] to initialize grpc creds

Dialing out without specifying TLS creds but giving https uses some
default behavior that depends on passing an endpoint with https to
Dial(), so it's not enough to completely rely on the balancer to supply
endpoints.

Fixes #8008

Also ctx-izes grpc.Dial
Anthony Romano 8 年 前
コミット
5ada311416
1 ファイル変更4 行追加2 行削除
  1. 4 2
      clientv3/client.go

+ 4 - 2
clientv3/client.go

@@ -322,7 +322,7 @@ func (c *Client) dial(endpoint string, dopts ...grpc.DialOption) (*grpc.ClientCo
 
 
 	opts = append(opts, c.cfg.DialOptions...)
 	opts = append(opts, c.cfg.DialOptions...)
 
 
-	conn, err := grpc.Dial(host, opts...)
+	conn, err := grpc.DialContext(c.ctx, host, opts...)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -367,7 +367,9 @@ func newClient(cfg *Config) (*Client, error) {
 	}
 	}
 
 
 	client.balancer = newSimpleBalancer(cfg.Endpoints)
 	client.balancer = newSimpleBalancer(cfg.Endpoints)
-	conn, err := client.dial("", grpc.WithBalancer(client.balancer))
+	// use Endpoints[0] so that for https:// without any tls config given, then
+	// grpc will assume the ServerName is in the endpoint.
+	conn, err := client.dial(cfg.Endpoints[0], grpc.WithBalancer(client.balancer))
 	if err != nil {
 	if err != nil {
 		client.cancel()
 		client.cancel()
 		client.balancer.Close()
 		client.balancer.Close()