Skip to content

Commit

Permalink
bugfix: cleanup dangling shim by brand new context
Browse files Browse the repository at this point in the history
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>
(cherry picked from commit 18e581d)
Signed-off-by: Wei Fu <fuweid89@gmail.com>
  • Loading branch information
fuweid committed Feb 25, 2020
1 parent 2d8cc40 commit e71c7d0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion runtime/v1/linux/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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")
}
}
Expand Down

0 comments on commit e71c7d0

Please sign in to comment.