From 8d15d384a203139234e2904460e2f5ebf7c9d301 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 7 Jan 2022 09:56:37 -0800 Subject: [PATCH] builtin/docker: fix crash during stop task with ODR A crash could occur if a container is already removing, since we set err to nil and then later check `err.Error()`. This crash causes no actual problems cause the container is already auto-removing, but it makes the logs noisier than they need to be. --- builtin/docker/task.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/builtin/docker/task.go b/builtin/docker/task.go index ae3062d0960..d8bf9a62998 100644 --- a/builtin/docker/task.go +++ b/builtin/docker/task.go @@ -292,15 +292,13 @@ func (b *TaskLauncher) StopTask( if err := cli.ContainerRemove(ctx, ti.Id, types.ContainerRemoveOptions{ Force: true, }); err != nil { - // "removal of container already in progress" is the error when - // the daemon is removing this for some reason (auto remove or - // other). This is not an error. if strings.Contains(err.Error(), "already in progress") { + // "removal of container already in progress" is the error when + // the daemon is removing this for some reason (auto remove or + // other). This is not an error. err = nil - } - - // Container is already removed - if strings.Contains(strings.ToLower(err.Error()), "no such container") { + } else if strings.Contains(strings.ToLower(err.Error()), "no such container") { + // Container is already removed err = nil } @@ -358,6 +356,7 @@ func (b *TaskLauncher) StartTask( "oci-url", tli.OciUrl, "arguments", tli.Arguments, "environment", env, + "autoremove", !b.config.DebugContainers, ) var memory int64