Skip to content

Commit

Permalink
Fix invalid wait condition on kill
Browse files Browse the repository at this point in the history
When using the compatability tests on kill, the kill
function goes into an infinite wait loop taking all of the CPU.

This change will use the correct wait function and exit properly.

Fixes: containers#9206

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Feb 3, 2021
1 parent 4ce8b12 commit d87f54f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/api/handlers/compat/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ func KillContainer(w http.ResponseWriter, r *http.Request) {
return
}
if sig == 0 || syscall.Signal(sig) == syscall.SIGKILL {
var opts entities.WaitOptions
if _, err := containerEngine.ContainerWait(r.Context(), []string{name}, opts); err != nil {
if _, err := utils.WaitContainer(w, r); err != nil {

utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
return
}
Expand Down
9 changes: 9 additions & 0 deletions test/python/docker/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ def test_stop_container(self):
top.reload()
self.assertIn(top.status, ("stopped", "exited"))

def test_kill_container(self):
top = self.client.containers.get(TestContainers.topContainerId)
self.assertEqual(top.status, "running")

# Kill a running container and validate the state
top.kill()
top.reload()
self.assertIn(top.status, ("stopped", "exited"))

def test_restart_container(self):
# Validate the container state
top = self.client.containers.get(TestContainers.topContainerId)
Expand Down

0 comments on commit d87f54f

Please sign in to comment.