Skip to content

Commit 18e581d

Browse files
committed
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 <fuweid89@gmail.com>
1 parent 0e08405 commit 18e581d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

runtime/v1/linux/runtime.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ const (
6262
configFilename = "config.json"
6363
defaultRuntime = "runc"
6464
defaultShim = "containerd-shim"
65+
66+
// cleanupTimeout is default timeout for cleanup operations
67+
cleanupTimeout = 1 * time.Minute
6568
)
6669

6770
func init() {
@@ -212,7 +215,10 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts
212215
}
213216
defer func() {
214217
if err != nil {
215-
if kerr := s.KillShim(ctx); kerr != nil {
218+
deferCtx, deferCancel := context.WithTimeout(
219+
namespaces.WithNamespace(context.TODO(), namespace), cleanupTimeout)
220+
defer deferCancel()
221+
if kerr := s.KillShim(deferCtx); kerr != nil {
216222
log.G(ctx).WithError(err).Error("failed to kill shim")
217223
}
218224
}

0 commit comments

Comments
 (0)