Merge pull request #1207 from Random-Liu/move-cancel
Move context cancel into defer.
This commit is contained in:
commit
994cea830b
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user