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

Using waitExitOrRemoved for docker start #25861

Merged
merged 1 commit into from
Aug 26, 2016

Conversation

WeiZhang555
Copy link
Contributor

Currently start command will invoke getExitCode - which is based on
Inspect API - to get returned exit code after container exits, there's
two race conditions here:

  1. if container is started with Restart Policy, there's chance that the
    container is restarted quickly before it calls getExitCode, under such
    circumstance, the exit code is wrong.
  2. if container is started with --rm, it's possible that container is
    removed before getExitCode, in this situation, you can't get correct
    exit code either.

Replace getExitCode with waitExitOrRemoved can solve this problem.

Signed-off-by: Zhang Wei zhangwei555@huawei.com

@WeiZhang555 WeiZhang555 force-pushed the wait-remove-for-start branch 6 times, most recently from 18c9089 to c9d18a6 Compare August 19, 2016 10:00
// no matter it's detached, removed on daemon side(--rm) or exit normally.
statusChan, err := waitExitOrRemoved(dockerCli, context.Background(), c.ID, c.HostConfig.AutoRemove)
if err != nil {
return fmt.Errorf("Error waiting container's exit code: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

We may want to store this error and return it later (instead of waiting on the status chan), or at least improve the error message since it's weird to say that you couldn't wait on a container's exit code before it's even started.

@WeiZhang555
Copy link
Contributor Author

@cpuguy83 How about this one.
PS: win2lin test case failure is unrelated

if err := dockerCli.Client().ContainerStart(ctx, c.ID, types.ContainerStartOptions{}); err != nil {
cancelFun()
<-cErr
if c.HostConfig.AutoRemove {
// wait container to be removed
<-statusChan
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to check if statusErr != nil first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. I will change it to

if c.HostConfig.AutoRemove && statusErr == nil { ... }

@WeiZhang555
Copy link
Contributor Author

@cpuguy83 updated as per your suggestion. PTAL. 😄

return err

if statusErr != nil {
return fmt.Errorf("Can't get container's exit code: %v", statusErr)
Copy link
Member

Choose a reason for hiding this comment

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

Errors should start with lower case

@cpuguy83
Copy link
Member

One minor nit otherwise LGTM.

Currently start command will invoke getExitCode - which is based on
Inspect API - to get returned exit code after container exits.
There's two race conditions here:

if container is started with Restart Policy, there's chance that the
container is restarted quickly before it calls getExitCode, under such
circumstance, the exit code is wrong.

if container is started with --rm, it's possible that container is
removed before getExitCode, in this situation, you can't get correct
exit code either.

Replace getExitCode with waitExitOrRemoved can solve this problem.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
@WeiZhang555
Copy link
Contributor Author

@cpuguy83 fixed

@tonistiigi
Copy link
Member

LGTM

@LK4D4
Copy link
Contributor

LK4D4 commented Aug 26, 2016

LGTM

@LK4D4 LK4D4 merged commit bdadcfc into moby:master Aug 26, 2016
@WeiZhang555 WeiZhang555 deleted the wait-remove-for-start branch August 27, 2016 00:09
@thaJeztah thaJeztah added this to the 1.13.0 milestone Sep 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants