-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Conversation
18c9089
to
c9d18a6
Compare
// 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) |
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.
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.
c9d18a6
to
ae165ec
Compare
@cpuguy83 How about this one. |
if err := dockerCli.Client().ContainerStart(ctx, c.ID, types.ContainerStartOptions{}); err != nil { | ||
cancelFun() | ||
<-cErr | ||
if c.HostConfig.AutoRemove { | ||
// wait container to be removed | ||
<-statusChan |
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.
Do we need to check if statusErr != nil
first?
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.
Correct. I will change it to
if c.HostConfig.AutoRemove && statusErr == nil { ... }
ae165ec
to
0559e70
Compare
@cpuguy83 updated as per your suggestion. PTAL. 😄 |
return err | ||
|
||
if statusErr != nil { | ||
return fmt.Errorf("Can't get container's exit code: %v", statusErr) |
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.
Errors should start with lower case
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>
0559e70
to
b8464c1
Compare
@cpuguy83 fixed |
LGTM |
LGTM |
Currently
start
command will invokegetExitCode
- which is based onInspect
API - to get returned exit code after container exits, there'stwo race conditions here:
container is restarted quickly before it calls
getExitCode
, under suchcircumstance, the exit code is wrong.
--rm
, it's possible that container isremoved before
getExitCode
, in this situation, you can't get correctexit code either.
Replace
getExitCode
withwaitExitOrRemoved
can solve this problem.Signed-off-by: Zhang Wei zhangwei555@huawei.com