Merge pull request #208 from tonistiigi/fix-cancel

containerd: fix cancellation issue
docker-18.09
Akihiro Suda 2017-12-13 12:58:08 +09:00 committed by GitHub
commit 9dee46bbfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

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