From 18e581dd91fd671aaeba86dcae2b6c97142a1cb0 Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Fri, 21 Feb 2020 15:25:09 +0800 Subject: [PATCH] bugfix: cleanup dangling shim by brand new context When there is timeout or cancel for create container, killShim will fail because of canceled context. The shim will be dangling and unmanageable. Need to use new context to do cleanup. Signed-off-by: Wei Fu --- runtime/v1/linux/runtime.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/runtime/v1/linux/runtime.go b/runtime/v1/linux/runtime.go index fdaff5f9e..b2101f326 100644 --- a/runtime/v1/linux/runtime.go +++ b/runtime/v1/linux/runtime.go @@ -62,6 +62,9 @@ const ( configFilename = "config.json" defaultRuntime = "runc" defaultShim = "containerd-shim" + + // cleanupTimeout is default timeout for cleanup operations + cleanupTimeout = 1 * time.Minute ) func init() { @@ -212,7 +215,10 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts } defer func() { 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") } }