Merge pull request #4048 from fuweid/me-use-new-ctx-to-cleanup

bugfix: cleanup dangling shim by brand new context
This commit is contained in:
Phil Estes 2020-02-24 16:52:15 -05:00 committed by GitHub
commit 9b4967bd6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,6 +62,9 @@ const (
configFilename = "config.json" configFilename = "config.json"
defaultRuntime = "runc" defaultRuntime = "runc"
defaultShim = "containerd-shim" defaultShim = "containerd-shim"
// cleanupTimeout is default timeout for cleanup operations
cleanupTimeout = 1 * time.Minute
) )
func init() { func init() {
@ -212,7 +215,10 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts
} }
defer func() { defer func() {
if err != nil { if err != nil {
if kerr := s.KillShim(ctx); kerr != nil { deferCtx, deferCancel := context.WithTimeout(
namespaces.WithNamespace(context.TODO(), namespace), cleanupTimeout)
defer deferCancel()
if kerr := s.KillShim(deferCtx); kerr != nil {
log.G(ctx).WithError(err).Error("failed to kill shim") log.G(ctx).WithError(err).Error("failed to kill shim")
} }
} }