@@ -191,18 +191,13 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts
191191 }
192192 exitHandler := func () {
193193 log .G (ctx ).WithField ("id" , id ).Info ("shim reaped" )
194- t , err := r . tasks . Get ( ctx , id )
195- if err != nil {
194+
195+ if _ , err := r . tasks . Get ( ctx , id ); err != nil {
196196 // Task was never started or was already successfully deleted
197197 return
198198 }
199- lc := t .(* Task )
200199
201- log .G (ctx ).WithFields (logrus.Fields {
202- "id" : id ,
203- "namespace" : namespace ,
204- }).Warn ("cleaning up after killed shim" )
205- if err = r .cleanupAfterDeadShim (context .Background (), bundle , namespace , id , lc .pid ); err != nil {
200+ if err = r .cleanupAfterDeadShim (context .Background (), bundle , namespace , id ); err != nil {
206201 log .G (ctx ).WithError (err ).WithFields (logrus.Fields {
207202 "id" : id ,
208203 "namespace" : namespace ,
@@ -342,12 +337,12 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
342337 ctx = namespaces .WithNamespace (ctx , ns )
343338 pid , _ := runc .ReadPidFile (filepath .Join (bundle .path , proc .InitPidFile ))
344339 s , err := bundle .NewShimClient (ctx , ns , ShimConnect (r .config , func () {
345- _ , err := r .tasks .Get (ctx , id )
346- if err != nil {
340+ if _ , err := r .tasks .Get (ctx , id ); err != nil {
347341 // Task was never started or was already successfully deleted
348342 return
349343 }
350- if err := r .cleanupAfterDeadShim (ctx , bundle , ns , id , pid ); err != nil {
344+
345+ if err := r .cleanupAfterDeadShim (ctx , bundle , ns , id ); err != nil {
351346 log .G (ctx ).WithError (err ).WithField ("bundle" , bundle .path ).
352347 Error ("cleaning up after dead shim" )
353348 }
@@ -357,7 +352,7 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
357352 "id" : id ,
358353 "namespace" : ns ,
359354 }).Error ("connecting to shim" )
360- err := r .cleanupAfterDeadShim (ctx , bundle , ns , id , pid )
355+ err := r .cleanupAfterDeadShim (ctx , bundle , ns , id )
361356 if err != nil {
362357 log .G (ctx ).WithError (err ).WithField ("bundle" , bundle .path ).
363358 Error ("cleaning up after dead shim" )
@@ -407,7 +402,13 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
407402 return o , nil
408403}
409404
410- func (r * Runtime ) cleanupAfterDeadShim (ctx context.Context , bundle * bundle , ns , id string , pid int ) error {
405+ func (r * Runtime ) cleanupAfterDeadShim (ctx context.Context , bundle * bundle , ns , id string ) error {
406+ log .G (ctx ).WithFields (logrus.Fields {
407+ "id" : id ,
408+ "namespace" : ns ,
409+ }).Warn ("cleaning up after shim dead" )
410+
411+ pid , _ := runc .ReadPidFile (filepath .Join (bundle .path , proc .InitPidFile ))
411412 ctx = namespaces .WithNamespace (ctx , ns )
412413 if err := r .terminate (ctx , bundle , ns , id ); err != nil {
413414 if r .config .ShimDebug {
@@ -430,6 +431,10 @@ func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns,
430431 if err := bundle .Delete (); err != nil {
431432 log .G (ctx ).WithError (err ).Error ("delete bundle" )
432433 }
434+ // kill shim
435+ if shimPid , err := runc .ReadPidFile (filepath .Join (bundle .path , "shim.pid" )); err == nil && shimPid > 0 {
436+ unix .Kill (shimPid , unix .SIGKILL )
437+ }
433438
434439 r .events .Publish (ctx , runtime .TaskDeleteEventTopic , & eventstypes.TaskDelete {
435440 ContainerID : id ,
0 commit comments