-
Notifications
You must be signed in to change notification settings - Fork 18.8k
docker kill should return error if container is not running. #12371
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
Conversation
I think is a dup #12085 |
Also #12085 (comment) |
We currently are returning errors from kill, so I don't agree with this statement. We can steal the unit test code from the other patch. docker kill --signal 30 MISSINGCONTAINER Currently returns an error. This change just adds docker kill --signal 30 NOTRUNNINGCONTAINER The other pull request returned error on SIGINT of a non running container, which I left as not an error, |
This fix is in response to a bugzilla |
@@ -203,7 +203,7 @@ func postContainersKill(eng *engine.Engine, version version.Version, w http.Resp | |||
name := vars["name"] | |||
|
|||
// If we have a signal, look at it. Otherwise, do nothing | |||
if sigStr := vars["signal"]; sigStr != "" { | |||
if sigStr := r.Form.Get("signal"); sigStr != "" { |
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.
Sorry, I don't understand how this change relates to the PR? It seems it should never have been fetched from vars
, but then how does kill
even works today, and why is there no test to catch this?
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.
I think this is a real bug becuase signal comes from the GET params and not any URL segment
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, when testing the fix, a patch came in that blew up our fix. So I included it in the pull request.
LGTM |
can we get some testcases for this? |
Added a test. |
@rhatdan I don't see the test, did you forget to "git add" it? |
@duglin oops |
@@ -26,6 +26,11 @@ func (s *DockerSuite) TestKillContainer(c *check.C) { | |||
c.Fatalf("failed to kill container: %s, %v", out, err) | |||
} | |||
|
|||
/* Container should be stopped, second kill should return an error */ | |||
if _, _, err = runCommandWithOutput(killCmd); err == nil { |
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.
This will always error because you can't run the same cmd twice.
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.
it might be better to create a new test where you:
- create a container
- stop it
- try to kill it and then check for your new error message.
I think its important to make sure that we run, and verify, that the code you added is hit.
Ok added a new function. |
|
||
killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID) | ||
/* Container should be stopped, second kill should return an error */ | ||
if _, _, err = runCommandWithOutput(killCmd); err == nil { |
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.
Can you check to make sure your text is displayed? Otherwise we can't be sure we're hitting your code - it could have failed for some other reason by mistake.
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.
I don't think you addressed this comment yet
|
Ok this is broken, because we are only returning error on kill signal not on kill -9. I have fixed the test. |
Docker-DCO-1.1-Signed-off-by: Dan Walsh <dwalsh@redhat.com> (github: rhatdan)
@rhatdan any chance of you addressing #12371 (comment) ? |
@duglin I think the current pull request fails on all kill signals. |
ping @rhatdan any update here? |
@cpuguy83 I think it is all set? I have it returning errors for both kinds of kills. |
c.Fatalf("kill succeeded on a stopped container") | ||
} | ||
|
||
deleteContainer(cleanedContainerID) |
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.
No need for this delete here.
Docker-DCO-1.1-Signed-off-by: Dan Walsh <dwalsh@redhat.com> (github: rhatdan)
|
||
killCmd := exec.Command(dockerBinary, "kill", "-s", "30", cleanedContainerID) | ||
_, _, err = runCommandWithOutput(killCmd) | ||
c.Assert(err, check.Not(check.IsNil), check.Commentf("Kill succeeded on a stopped container")) |
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.
I don't think this addresses the previous comment, you're not checking the output to make sure you get the new error message you're generating.
Docker-DCO-1.1-Signed-off-by: Dan Walsh <dwalsh@redhat.com> (github: rhatdan)
The failure looks unrelated to the pull request. |
Any movement on this one? Seems like a fairly simple patch to merge. |
LGTM |
1 similar comment
LGTM |
docker kill should return error if container is not running.
Thanks. |
I just want to note that here #12085 (comment) we talked about breaking Kill api and I'm just wondering if we should version this change |
And also with this change not only container kill changes its behavior but also delete (and stop iirc) |
Assuming that docker kill is trying to actually kill the container is a mistake. If the container is not running we should report it back to the caller as a error.
Docker-DCO-1.1-Signed-off-by: Regan McCooey rmccooey27@aol.com (github: rmccooey27)
Docker-DCO-1.1-Signed-off-by: Dan Walsh dwalsh@redhat.com (github: rhatdan)