From 8ae0f94cd778062137fa7c852281a011af0b4928 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Fri, 12 Aug 2016 09:42:18 -0700 Subject: [PATCH] clientv3: only block on New() when DialTimeout > 0 Fixes #6162 --- clientv3/client.go | 12 +++++++----- clientv3/client_test.go | 9 +++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/clientv3/client.go b/clientv3/client.go index 66d5a3c0f96..ab6182c889d 100644 --- a/clientv3/client.go +++ b/clientv3/client.go @@ -138,11 +138,13 @@ func (c *Client) dialTarget(endpoint string) (proto string, host string, creds * return } -// dialSetupOpts gives the dial opts prioer to any authentication -func (c *Client) dialSetupOpts(endpoint string, dopts ...grpc.DialOption) []grpc.DialOption { - opts := []grpc.DialOption{ - grpc.WithBlock(), - grpc.WithTimeout(c.cfg.DialTimeout), +// dialSetupOpts gives the dial opts prior to any authentication +func (c *Client) dialSetupOpts(endpoint string, dopts ...grpc.DialOption) (opts []grpc.DialOption) { + if c.cfg.DialTimeout > 0 { + opts = []grpc.DialOption{ + grpc.WithTimeout(c.cfg.DialTimeout), + grpc.WithBlock(), + } } opts = append(opts, dopts...) diff --git a/clientv3/client_test.go b/clientv3/client_test.go index 63ff8146e18..158ec70369e 100644 --- a/clientv3/client_test.go +++ b/clientv3/client_test.go @@ -56,6 +56,15 @@ func TestDialTimeout(t *testing.T) { } } +func TestDialNoTimeout(t *testing.T) { + cfg := Config{Endpoints: []string{"127.0.0.1:12345"}} + c, err := New(cfg) + if c == nil || err != nil { + t.Fatalf("new client with DialNoWait should succeed, got %v", err) + } + c.Close() +} + func TestIsHaltErr(t *testing.T) { if !isHaltErr(nil, fmt.Errorf("etcdserver: some etcdserver error")) { t.Errorf(`error prefixed with "etcdserver: " should be Halted by default`)