From 57e10439d9d1d66492ae55e48af713d9a7a4c6f8 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Thu, 2 Sep 2021 03:58:20 -0700 Subject: [PATCH] Fixes task kill --force on Windows Process.Kill might still return an IsNotFound error, even if it actually killed the process. We should wait for the process to finish in the first place. Otherwise, when querying the task's status, we might still see it running, resulting in an error. Signed-off-by: Claudiu Belu --- task_opts.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/task_opts.go b/task_opts.go index e8d99eb51..2af443c3a 100644 --- a/task_opts.go +++ b/task_opts.go @@ -158,7 +158,17 @@ func WithProcessKill(ctx context.Context, p Process) error { return err } if err := p.Kill(ctx, syscall.SIGKILL, WithKillAll); err != nil { - if errdefs.IsFailedPrecondition(err) || errdefs.IsNotFound(err) { + // Kill might still return an IsNotFound error, even if it actually + // killed the process. + if errdefs.IsNotFound(err) { + select { + case <-ctx.Done(): + return ctx.Err() + case <-s: + return nil + } + } + if errdefs.IsFailedPrecondition(err) { return nil } return err