12891: Use docker "rm -f" instead of "stop" to cancel container.
authorTom Clegg <tclegg@veritasgenetics.com>
Mon, 22 Jan 2018 15:57:18 +0000 (10:57 -0500)
committerTom Clegg <tclegg@veritasgenetics.com>
Mon, 22 Jan 2018 17:34:03 +0000 (12:34 -0500)
"Stop" sends SIGTERM and then (after a timeout) SIGKILL to the main
process in the container. If the contained process catches SIGTERM,
the outcome depends on how much cleanup it manages to do in the
timeout period. We prefer a more predictable SIGKILL outcome.

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

services/crunch-run/crunchrun.go
services/crunch-run/crunchrun_test.go

index 45e48c2b8a4bb1b1713a899f5bd6bdbad5614c4e..a249273095c5909e49ed83d6148cdd54a2811386 100644 (file)
@@ -75,7 +75,7 @@ type ThinDockerClient interface {
        ContainerCreate(ctx context.Context, config *dockercontainer.Config, hostConfig *dockercontainer.HostConfig,
                networkingConfig *dockernetwork.NetworkingConfig, containerName string) (dockercontainer.ContainerCreateCreatedBody, error)
        ContainerStart(ctx context.Context, container string, options dockertypes.ContainerStartOptions) error
-       ContainerStop(ctx context.Context, container string, timeout *time.Duration) error
+       ContainerRemove(ctx context.Context, container string, options dockertypes.ContainerRemoveOptions) error
        ContainerWait(ctx context.Context, container string, condition dockercontainer.WaitCondition) (<-chan dockercontainer.ContainerWaitOKBody, <-chan error)
        ImageInspectWithRaw(ctx context.Context, image string) (dockertypes.ImageInspect, []byte, error)
        ImageLoad(ctx context.Context, input io.Reader, quiet bool) (dockertypes.ImageLoadResponse, error)
@@ -165,11 +165,10 @@ func (runner *ContainerRunner) stop() {
                return
        }
        runner.cCancelled = true
-       runner.CrunchLog.Printf("stopping container")
-       timeout := 10 * time.Second
-       err := runner.Docker.ContainerStop(context.TODO(), runner.ContainerID, &timeout)
+       runner.CrunchLog.Printf("removing container")
+       err := runner.Docker.ContainerRemove(context.TODO(), runner.ContainerID, dockertypes.ContainerRemoveOptions{Force: true})
        if err != nil {
-               runner.CrunchLog.Printf("error stopping container: %s", err)
+               runner.CrunchLog.Printf("error removing container: %s", err)
        }
 }
 
index a524e481d1bb014dbe8cc35fc111a70f4ce4fdd7..a17dff38092553137f0c7be54405582a2ed4bc0a 100644 (file)
@@ -152,7 +152,7 @@ func (t *TestDockerClient) ContainerStart(ctx context.Context, container string,
        }
 }
 
-func (t *TestDockerClient) ContainerStop(ctx context.Context, container string, timeout *time.Duration) error {
+func (t *TestDockerClient) ContainerRemove(ctx context.Context, container string, options dockertypes.ContainerRemoveOptions) error {
        t.stop <- true
        return nil
 }