Browse code

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 <liruilin4@huawei.com>
(cherry picked from commit da574f93432e600fda561da5e6983e7f69b364a9)
Signed-off-by: Dani Louca <dani.louca@docker.com>

Ruilin Li authored on 2018/06/11 18:59:26
Showing 2 changed files
... ...
@@ -64,8 +64,6 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int)
64 64
 	container.Lock()
65 65
 	defer container.Unlock()
66 66
 
67
-	daemon.stopHealthchecks(container)
68
-
69 67
 	if !container.Running {
70 68
 		return errNotRunning(container.ID)
71 69
 	}
... ...
@@ -165,3 +165,29 @@ ENTRYPOINT /bin/sh -c "sleep 600"`))
165 165
 	waitForHealthStatus(c, name, "starting", "healthy")
166 166
 
167 167
 }
168
+
169
+// GitHub #37263
170
+func (s *DockerSuite) TestHealthKillContainer(c *check.C) {
171
+	testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows
172
+
173
+	imageName := "testhealth"
174
+	buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox
175
+HEALTHCHECK --interval=1s --timeout=5s --retries=5 CMD /bin/sh -c "sleep 1"
176
+ENTRYPOINT /bin/sh -c "sleep 600"`))
177
+
178
+	name := "test_health_kill"
179
+	dockerCmd(c, "run", "-d", "--name", name, imageName)
180
+	defer func() {
181
+		dockerCmd(c, "rm", "-f", name)
182
+		dockerCmd(c, "rmi", imageName)
183
+	}()
184
+
185
+	// Start
186
+	dockerCmd(c, "start", name)
187
+	waitForHealthStatus(c, name, "starting", "healthy")
188
+
189
+	dockerCmd(c, "kill", "-s", "SIGINT", name)
190
+	out, _ := dockerCmd(c, "inspect", "--format={{.State.Health.Status}}", name)
191
+	c.Check(out, checker.Equals, "healthy\n")
192
+
193
+}