Skip to content

Conversation

@Random-Liu
Copy link
Member

@Random-Liu Random-Liu commented Aug 4, 2017

Although Dockershim doesn't actually support ExecSync timeout (see here), we should set the timeout, so that the other runtime which supports the timeout could work properly.

Fixes #50389.

/cc @yujuhong @timstclair @feiskyer

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 4, 2017
Copy link
Member

@feiskyer feiskyer left a comment

Choose a reason for hiding this comment

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

LGTM

// Do not set timeout when timeout is 0.
ctx, cancel = getContextWithCancel()
// Do not set timeout when timeout is 0.
ctx, cancel := getContextWithCancel()
Copy link
Member

Choose a reason for hiding this comment

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

getContextWithCancel does a bunch of stuff. We should avoid calling it if it's not going to be used (i.e. move this into an else block)

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, not much, it just returns context.WithCancel(context.Background())

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but context.WithCancel potentially brings up a go routine. It might be trivial, but it's better practice not to do unecessary work when it's easily avoidable..

Copy link
Member

Choose a reason for hiding this comment

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

Good point

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@k8s-github-robot k8s-github-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. release-note-label-needed labels Aug 5, 2017
@Random-Liu Random-Liu added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Aug 5, 2017
var cancel context.CancelFunc
if timeout != 0 {
// Use timeout + default timeout (2 minutes) as timeout.
ctx, cancel = getContextWithTimeout(r.timeout + time.Duration(timeout)*time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you multiple the user pass in timeout with time.Second?

Not sure this is the effect you want here, see https://play.golang.org/p/4hJFFXqoga

Copy link
Contributor

Choose a reason for hiding this comment

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

we probably need a unit test for this if this is indeed an issue.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch. It looks like timeout is already a Duration?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copied the code from StopContainer. Yeah, there is a mismatch. timeout in StopContainer is int64.

Will update this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Random-Liu Is it possible to add a unit test for this?

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 9, 2017
var cancel context.CancelFunc
if timeout != 0 {
// Use timeout + default timeout (2 minutes) as timeout.
ctx, cancel = getContextWithTimeout(r.timeout + timeout*time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

Why are you multiplying the timeout by time.Second? That should have been done by the caller. I'd expect it to just be passed through here...

Copy link
Member Author

Choose a reason for hiding this comment

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

My fault.

var ctx context.Context
var cancel context.CancelFunc
if timeout != 0 {
// Use timeout + default timeout (2 minutes) as timeout.
Copy link
Member

Choose a reason for hiding this comment

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

It seems a little odd to add the timeout with the default here? Can you explain the reasoning?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same with stop, we want to leave some time for the runtime to do cleanup.
Runtime can't finish running immediately when timeout exceed.

// Use timeout + default timeout (2 minutes) as timeout.
ctx, cancel = getContextWithTimeout(r.timeout + timeout*time.Second)
} else {
ctx, cancel = getContextWithCancel()
Copy link
Member

Choose a reason for hiding this comment

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

Should this use the default timeout?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. We should not set any timeout by default because exec may take long time.

@Random-Liu
Copy link
Member Author

@yujuhong Sorry, I forgot to push my local fix. Pushed newest fix.

@yujuhong
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 17, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Random-Liu, yujuhong

Associated issue: 50389

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@Random-Liu
Copy link
Member Author

@yujuhong Thanks for reviewing!

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 50536, 50809, 50220, 50399, 50176)

@k8s-github-robot k8s-github-robot merged commit d490e2c into kubernetes:master Aug 18, 2017
@Random-Liu Random-Liu deleted the set-exec-timeout branch August 25, 2017 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants