Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NewWithTimeout(cfg Config) (*Client, error) #6479

Closed
zbindenren opened this issue Sep 20, 2016 · 1 comment
Closed

Add NewWithTimeout(cfg Config) (*Client, error) #6479

zbindenren opened this issue Sep 20, 2016 · 1 comment

Comments

@zbindenren
Copy link
Contributor

Hi

First of all: thanks for that great software!

I tried to write a etcd cluster health check for a tool we are creating.

I was inspired by the code in etcdctl. And I noticed a strange behavior in the clients New method, when the etcd daemon is not running.

Here the test:

var endoints = []string{"localhost:1111"} // nothing is listening here

func TestHealth(t *testing.T) {
    ep := endoints[0]
    cli, err := clientv3.New(clientv3.Config{
        Endpoints:   []string{ep},
    })
    fmt.Println("code never gets here")
    if err != nil {
        t.Errorf("ep %s unhealthy: %s", ep, err)
    }
    ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
    _, err = cli.Get(ctx, "/mule-test/health")
    fmt.Println("never gets called")
    cancel()
    if err != nil {
        t.Errorf("ep %s unhealthy: %s", ep, err)
    }
    fmt.Printf("ep %s is healthy", ep)

}

I see the following endpoint:

2016/09/20 07:32:23 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: dial tcp [::1]:1111: getsockopt: connection refused"; Reconnecting to {"localhost:1111" <nil>}
2016/09/20 07:32:24 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: dial tcp [::1]:1111: getsockopt: connection refused"; Reconnecting to {"localhost:1111" <nil>}
2016/09/20 07:32:26 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: dial tcp [::1]:1111: getsockopt: connection refused"; Reconnecting to {"localhost:1111" <nil>}

Test hangs until timeout.

As workaround I can use net.DialTimeout(network, address string, timeout time.Duration).

It was just surprising to me and I was wondering if this is wanted behavior.

@heyitsanthony
Copy link
Contributor

It's hanging because clientv3.New used to block until it could establish a connection to the cluster. It now only blocks if a DialTimeout is given. Cf. #6162 for more background. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants