-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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: add timeout to snapshot save command #10301
etcdctl: add timeout to snapshot save command #10301
Conversation
} else { | ||
// if user does not specify "--command-timeout" flag, there will be no timeout for snapshot save command | ||
ctx, cancel = context.WithCancel(context.Background()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like you could condense this a bit.
ctx, cancel := context.WithCancel(context.Background())
if ifCommandTimeoutFlagSet(cmd) {
ctx, cancel = commandCtx(cmd)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
etcdctl/ctlv3/command/util.go
Outdated
@@ -82,6 +82,14 @@ func commandCtx(cmd *cobra.Command) (context.Context, context.CancelFunc) { | |||
return context.WithTimeout(context.Background(), timeOut) | |||
} | |||
|
|||
func ifCommandTimeoutFlagSet(cmd *cobra.Command) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isCommandTimeoutFlagSet
etcdctl/ctlv3/command/util.go
Outdated
func ifCommandTimeoutFlagSet(cmd *cobra.Command) bool { | ||
commandTimeoutFlag := cmd.Flags().Lookup("command-timeout") | ||
if commandTimeoutFlag == nil { | ||
ExitWithError(ExitError, fmt.Errorf("expect command-timeout flag to exist")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably we should panic here. this is an internal error.
lgtm after fixing the issues in the comments. |
Codecov Report
@@ Coverage Diff @@
## master #10301 +/- ##
==========================================
- Coverage 71.93% 71.65% -0.29%
==========================================
Files 391 391
Lines 36386 36400 +14
==========================================
- Hits 26176 26084 -92
- Misses 8414 8495 +81
- Partials 1796 1821 +25
Continue to review full report at Codecov.
|
snapshot save command by default has no timeout, but respects user specified command timeout.
bfcb5d3
to
5b6b03d
Compare
@xiang90 Thanks for the review. All fixed. |
Also let's add a changelog https://github.com/etcd-io/etcd/blob/master/CHANGELOG-3.4.md#etcdctl-v3. |
@gyuho Sure. Thanks for reminding:) |
CHANGELOG-3.4: update from #10301
Snapshot save command by default has no timeout, but should respect user specified command timeout.
Fix #10298
/cc @jpbetz @gyuho @xiang90