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 <cbelu@cloudbasesolutions.com>
This commit is contained in:
Claudiu Belu 2021-09-02 03:58:20 -07:00
parent d58542a9d1
commit 57e10439d9

View File

@ -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