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: use user specified timeout value for entire command execution #3530

Merged
merged 1 commit into from
Sep 28, 2015

Conversation

mitake
Copy link
Contributor

@mitake mitake commented Sep 15, 2015

etcdctl should be capable to use a user specified timeout value for
total command execution, not only per request timeout. This commit
adds a new option --total-timeout to the command. The value passed via
this option is used as a timeout value of entire command execution.

Fixes coreos#3517

This is the new version of the PR #3518 . This new one is so different from the old one, so I made a new PR.

@mitake mitake changed the title etcdctl: use user specified timeout value for entire RPC etcdctl: use user specified timeout value for entire command execution Sep 15, 2015
@mitake
Copy link
Contributor Author

mitake commented Sep 19, 2015

ping? @xiang90 @yichengq (if you already noticed this pr, sorry for noise)

@yichengq
Copy link
Contributor

I don't like current approach because it introduces new parameter in each function call, and it has one more level indirection.

Could we use
ctx, cancel := context.WithTimeout(context.Background(), c.GlobalDuration("total-timeout")) in each function and use the same ctx for the whole function to achieve this?

@mitake
Copy link
Contributor Author

mitake commented Sep 22, 2015

@yichengq thanks for your review. However, current approach can reduce possibility of using wrong timeout value for each context (the problem this PR is trying to fix). So I thought introducing a new wrapper function actionWithTotalTimeout() is valuable. And commands which doesn't require total timeout aren't changed.

Of course, if you prefer declaration of ctx in each function, I'll pick your approach.

@yichengq
Copy link
Contributor

I still prefer to declare ctx. Current solution makes the code hard to read, and the indirection could be replaced by one-line declaration.

possibility of using wrong timeout value for each context

We could add a function to return overall context and its cancel.

And commands which doesn't require total timeout aren't changed.

I think other commands need to have total timeout too. They are using context.TODO now.

@mitake
Copy link
Contributor Author

mitake commented Sep 24, 2015

@yichengq ok, I'll change this PR based on your policy later

@mitake mitake force-pushed the etcdctl-timeout-v2 branch 2 times, most recently from 82407bb to b4847d4 Compare September 24, 2015 04:53
@mitake
Copy link
Contributor Author

mitake commented Sep 24, 2015

@yichengq updated based on the policy

@@ -86,9 +86,8 @@ func actionMemberAdd(c *cli.Context) {
mAPI := mustNewMembersAPI(c)

url := args[1]
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.

I would defer cancel() here. It is reasonable because the ctx is for the whole function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

defer cancel() seems nice, I'll fix it.

@mitake
Copy link
Contributor Author

mitake commented Sep 25, 2015

@yichengq updated based on your comments

@mitake
Copy link
Contributor Author

mitake commented Sep 25, 2015

updated the commit log a little bit

totalCtx, totalCancel := contextWithTotalTimeout(c)
defer totalCancel()

ctx, cancel := contextWithPerRequestTimeout(c, totalCtx)
Copy link
Contributor

Choose a reason for hiding this comment

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

The per request timeout is used at https://github.com/coreos/etcd/blob/master/etcdctl/command/util.go#L251. It is the timeout for each HTTP request(ref: http://godoc.org/github.com/coreos/etcd/client#Config). When we call mAPI.Add, it may include several HTTP requests, so we cannot set per request timeout as its context.

It is fine that we just use totalCtx for all requests in the this function IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I misused client.DefaultRequestTimeout :( Thanks for pointing. I'll fix it.

@mitake
Copy link
Contributor Author

mitake commented Sep 28, 2015

@yichengq updated for using correct context and timeout

etcdctl should be capable to use a user specified timeout value for
total command execution, not only per request timeout. This commit
adds a new option --total-timeout to the command. The value passed via
this option is used as a timeout value of entire command execution.

Fixes coreos#3517
@yichengq
Copy link
Contributor

LGTM. Do you have plan to fix the left context.Background() ones? For example, https://github.com/coreos/etcd/blob/master/etcdctl/command/set_command.go#L58

@mitake
Copy link
Contributor Author

mitake commented Sep 28, 2015

@yichengq thanks for your review. Sure, I'd like to work on other parts. Should I fix them in this PR?

@yichengq
Copy link
Contributor

No. this one is good enough.

Thanks for the contribution! ❤️

yichengq added a commit that referenced this pull request Sep 28, 2015
etcdctl: use user specified timeout value for entire command execution
@yichengq yichengq merged commit 7410698 into etcd-io:master Sep 28, 2015
@mitake mitake deleted the etcdctl-timeout-v2 branch December 30, 2015 17:22
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