@@ -201,10 +201,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts
201201 "id" : id ,
202202 "namespace" : namespace ,
203203 }).Warn ("cleaning up after killed shim" )
204- err = r .cleanupAfterDeadShim (context .Background (), bundle , namespace , id , lc .pid )
205- if err == nil {
206- r .tasks .Delete (ctx , lc )
207- } else {
204+ if err = r .cleanupAfterDeadShim (context .Background (), bundle , namespace , id , lc .pid ); err != nil {
208205 log .G (ctx ).WithError (err ).WithFields (logrus.Fields {
209206 "id" : id ,
210207 "namespace" : namespace ,
@@ -313,7 +310,7 @@ func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, er
313310 }
314311 return nil , errdefs .FromGRPC (err )
315312 }
316- r .tasks .Delete (ctx , lc )
313+ r .tasks .Delete (ctx , lc . id )
317314 if err := lc .shim .KillShim (ctx ); err != nil {
318315 log .G (ctx ).WithError (err ).Error ("failed to kill shim" )
319316 }
@@ -383,7 +380,17 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
383380 )
384381 ctx = namespaces .WithNamespace (ctx , ns )
385382 pid , _ := runc .ReadPidFile (filepath .Join (bundle .path , proc .InitPidFile ))
386- s , err := bundle .NewShimClient (ctx , ns , ShimConnect (), nil )
383+ s , err := bundle .NewShimClient (ctx , ns , ShimConnect (func () {
384+ log .G (ctx ).WithError (err ).WithFields (logrus.Fields {
385+ "id" : id ,
386+ "namespace" : ns ,
387+ }).Error ("connecting to shim" )
388+ err := r .cleanupAfterDeadShim (ctx , bundle , ns , id , pid )
389+ if err != nil {
390+ log .G (ctx ).WithError (err ).WithField ("bundle" , bundle .path ).
391+ Error ("cleaning up after dead shim" )
392+ }
393+ }), nil )
387394 if err != nil {
388395 log .G (ctx ).WithError (err ).WithFields (logrus.Fields {
389396 "id" : id ,
@@ -433,6 +440,7 @@ func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns,
433440 ExitedAt : exitedAt ,
434441 })
435442
443+ r .tasks .Delete (ctx , id )
436444 if err := bundle .Delete (); err != nil {
437445 log .G (ctx ).WithError (err ).Error ("delete bundle" )
438446 }
@@ -448,12 +456,10 @@ func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns,
448456}
449457
450458func (r * Runtime ) terminate (ctx context.Context , bundle * bundle , ns , id string ) error {
451- ctx = namespaces .WithNamespace (ctx , ns )
452459 rt , err := r .getRuntime (ctx , ns , id )
453460 if err != nil {
454461 return err
455462 }
456-
457463 if err := rt .Delete (ctx , id , & runc.DeleteOpts {
458464 Force : true ,
459465 }); err != nil {
0 commit comments