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

etcdctl/ctlv2: total-timeout for Sync #5310

Merged
merged 1 commit into from
May 10, 2016
Merged

Conversation

gyuho
Copy link
Contributor

@gyuho gyuho commented May 10, 2016

Fix #4897.

@gyuho
Copy link
Contributor Author

gyuho commented May 10, 2016

/cc @xiang90 @kayrus

Please review.

Thanks.

@@ -156,7 +156,12 @@ func getTransport(c *cli.Context) (*http.Transport, error) {
CertFile: certfile,
KeyFile: keyfile,
}
return transport.NewTransport(tls, defaultDialTimeout)

to := c.GlobalDuration("total-timeout")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why shall we do this? say if the total-timeout is 10 seconds and the defaultDialTimeout is 5 seconds, the change might cause the dailtimeout to be rewrote by a longer one which is 10 seconds. this is incorrect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if totalTimeout !=0 && to < defaultDialTimeout {
dialTimeout = totalTimeout
}

/cc @gyuho

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xiang90 Did you mean

    to := c.GlobalDuration("total-timeout")
    if to != 0 && to > defaultDialTimeout {
        defaultDialTimeout = to
    }
    return transport.NewTransport(tls, defaultDialTimeout)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I meant:

    to := c.GlobalDuration("total-timeout")
    if to != 0 && to < defaultDialTimeout {
        defaultDialTimeout = to
    }
    return transport.NewTransport(tls, defaultDialTimeout)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no.
Your code has two issues:

  1. we should never modify the default variable in any case.
  2. we should keep the shorter timeout not longer. Say I want the total timeout to be 5 seconds, but the defaultDialtimeout is 30 seconds. I should give the transport a timeout of 5 seconds, not 30 seconds. Or dial might block for 30 seconds, which is longer than 5 seconds.
    dailTimeout := defaultDialTimeout 
    totalTimeout := c.GlobalDuration("total-timeout")
    if totalTimoeout != 0 && totalTimeout < defaultDialTimeout {
        defaultDialTimeout = totalTimeout
    }
    return transport.NewTransport(tls, defaultDialTimeout)

@gyuho
Copy link
Contributor Author

gyuho commented May 10, 2016

@xiang90 You are right. Just reverted it.

PTAL.

Thanks.

@@ -203,7 +203,7 @@ func mustNewClient(c *cli.Context) client.Client {
if debug {
fmt.Fprintf(os.Stderr, "start to sync cluster using endpoints(%s)\n", strings.Join(hc.Endpoints(), ","))
}
ctx, cancel := context.WithTimeout(context.Background(), client.DefaultRequestTimeout)
ctx, cancel := contextWithTotalTimeout(c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here, we should also add a timeout for the request timeout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xiang90

also here, we should also add a timeout for the request timeout.

Sorry, can you explain more? This already puts timeout for the command:

func contextWithTotalTimeout(c *cli.Context) (context.Context, context.CancelFunc) {
    return context.WithTimeout(context.Background(), c.GlobalDuration("total-timeout"))
}

c.GlobalDuration("timeout") is already used for HeaderTimeoutPerRequest here https://github.com/coreos/etcd/blob/master/etcdctl/ctlv2/command/util.go#L302

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xiang90
Copy link
Contributor

xiang90 commented May 10, 2016

Can you give it a try after the change? Does this fix the problem mentioned in #4897

@gyuho
Copy link
Contributor Author

gyuho commented May 10, 2016

@xiang90 Yeah, just pushed a change to address your last comment and tried

./bin/etcdctl --debug --timeout 5s --endpoint http://example.com:1234 ls /

start to sync cluster using endpoints(http://example.com:1234)
cURL Command: curl -X GET http://example.com:1234/v2/members
Error:  client: etcd cluster is unavailable or misconfigured
error #0: dial tcp 93.184.216.34:1234: i/o timeout

It times out after 5 seconds (not 30 seconds)

@xiang90
Copy link
Contributor

xiang90 commented May 10, 2016

lgtm

@gyuho
Copy link
Contributor Author

gyuho commented May 10, 2016

Thanks. Merging in greens.

@gyuho gyuho merged commit d8215c8 into etcd-io:master May 10, 2016
@gyuho gyuho deleted the timeout_v2 branch May 10, 2016 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants