Merge pull request #1207 from Random-Liu/move-cancel

Move context cancel into defer.
This commit is contained in:
Lantao Liu 2019-07-26 14:04:33 -07:00 committed by GitHub
commit 994cea830b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -135,18 +135,16 @@ func (c *criService) stopContainer(ctx context.Context, container containerstore
}
sigTermCtx, sigTermCtxCancel := context.WithTimeout(ctx, timeout)
defer sigTermCtxCancel()
err = c.waitContainerStop(sigTermCtx, container)
if err == nil {
// Container stopped on first signal no need for SIGKILL
sigTermCtxCancel()
return nil
}
// If the parent context was cancelled or exceeded return immediately
if ctx.Err() != nil {
sigTermCtxCancel()
return ctx.Err()
}
sigTermCtxCancel()
// sigTermCtx was exceeded. Send SIGKILL
logrus.Debugf("Stop container %q with signal %v timed out", id, sig)
}