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) sigTermCtx, sigTermCtxCancel := context.WithTimeout(ctx, timeout)
defer sigTermCtxCancel()
err = c.waitContainerStop(sigTermCtx, container) err = c.waitContainerStop(sigTermCtx, container)
if err == nil { if err == nil {
// Container stopped on first signal no need for SIGKILL // Container stopped on first signal no need for SIGKILL
sigTermCtxCancel()
return nil return nil
} }
// If the parent context was cancelled or exceeded return immediately // If the parent context was cancelled or exceeded return immediately
if ctx.Err() != nil { if ctx.Err() != nil {
sigTermCtxCancel()
return ctx.Err() return ctx.Err()
} }
sigTermCtxCancel()
// sigTermCtx was exceeded. Send SIGKILL // sigTermCtx was exceeded. Send SIGKILL
logrus.Debugf("Stop container %q with signal %v timed out", id, sig) logrus.Debugf("Stop container %q with signal %v timed out", id, sig)
} }