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