From 32802bc7d94639e79c5b959b20bf50ad6d7c8ac8 Mon Sep 17 00:00:00 2001 From: Ruilin Li Date: Mon, 11 Jun 2018 17:59:26 +0800 Subject: [PATCH] do not stop health check before sending signal Docker daemon always stops healthcheck before sending signal to a container now. However, when we use "docker kill" to send signals other than SIGTERM or SIGKILL to a container, such as SIGINT, daemon still stops container health check though container process handles the signal normally and continues to work. Signed-off-by: Ruilin Li (cherry picked from commit da574f93432e600fda561da5e6983e7f69b364a9) Signed-off-by: Dani Louca --- daemon/kill.go | 2 -- integration-cli/docker_cli_health_test.go | 26 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/daemon/kill.go b/daemon/kill.go index 3e97158a0c..0fe7412913 100644 --- a/daemon/kill.go +++ b/daemon/kill.go @@ -64,8 +64,6 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int) container.Lock() defer container.Unlock() - daemon.stopHealthchecks(container) - if !container.Running { return errNotRunning(container.ID) } diff --git a/integration-cli/docker_cli_health_test.go b/integration-cli/docker_cli_health_test.go index 4fb63994bb..6a94e6b61a 100644 --- a/integration-cli/docker_cli_health_test.go +++ b/integration-cli/docker_cli_health_test.go @@ -165,3 +165,29 @@ ENTRYPOINT /bin/sh -c "sleep 600"`)) waitForHealthStatus(c, name, "starting", "healthy") } + +// GitHub #37263 +func (s *DockerSuite) TestHealthKillContainer(c *check.C) { + testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows + + imageName := "testhealth" + buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox +HEALTHCHECK --interval=1s --timeout=5s --retries=5 CMD /bin/sh -c "sleep 1" +ENTRYPOINT /bin/sh -c "sleep 600"`)) + + name := "test_health_kill" + dockerCmd(c, "run", "-d", "--name", name, imageName) + defer func() { + dockerCmd(c, "rm", "-f", name) + dockerCmd(c, "rmi", imageName) + }() + + // Start + dockerCmd(c, "start", name) + waitForHealthStatus(c, name, "starting", "healthy") + + dockerCmd(c, "kill", "-s", "SIGINT", name) + out, _ := dockerCmd(c, "inspect", "--format={{.State.Health.Status}}", name) + c.Check(out, checker.Equals, "healthy\n") + +}