diff --git a/executor/containerdexecutor/executor.go b/executor/containerdexecutor/executor.go index aaa1c091..dbb147db 100644 --- a/executor/containerdexecutor/executor.go +++ b/executor/containerdexecutor/executor.go @@ -89,16 +89,19 @@ func (w containerdExecutor) Exec(ctx context.Context, meta executor.Meta, root c return err } - killCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - + var cancel func() ctxDone := ctx.Done() for { select { case <-ctxDone: ctxDone = nil + var killCtx context.Context + killCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second) task.Kill(killCtx, syscall.SIGKILL) case status := <-statusCh: - cancel() + if cancel != nil { + cancel() + } if status.ExitCode() != 0 { return errors.Errorf("process returned non-zero exit code: %d", status.ExitCode()) }