From 840016ea0504fb1c616a3af2f8d48bd16a7400f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Mon, 29 Apr 2024 16:33:03 +0200 Subject: [PATCH] waitExitOrRemoved: Handle context cancellation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- cli/command/container/utils.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli/command/container/utils.go b/cli/command/container/utils.go index 31b9df4aad63..9662ac027ffe 100644 --- a/cli/command/container/utils.go +++ b/cli/command/container/utils.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "strconv" "github.com/docker/docker/api/types" @@ -36,6 +37,8 @@ func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containe statusC := make(chan int) go func() { select { + case <-ctx.Done(): + return case result := <-resultC: if result.Error != nil { logrus.Errorf("Error waiting for container: %v", result.Error.Message) @@ -44,6 +47,9 @@ func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containe statusC <- int(result.StatusCode) } case err := <-errC: + if errors.Is(err, context.Canceled) { + return + } logrus.Errorf("error waiting for container: %v", err) statusC <- 125 }