From 4c1ffbcc45fd4a2703e12b405e8217cf9f56015f Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Tue, 12 Dec 2017 17:20:39 -0800 Subject: [PATCH] containerd: fix cancellation issue Signed-off-by: Tonis Tiigi --- executor/containerdexecutor/executor.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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()) }