@@ -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 ,
@@ -338,12 +333,12 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
338333 ctx = namespaces .WithNamespace (ctx , ns )
339334 pid , _ := runc .ReadPidFile (filepath .Join (bundle .path , proc .InitPidFile ))
340335 s , err := bundle .NewShimClient (ctx , ns , ShimConnect (r .config , func () {
341- _ , err := r .tasks .Get (ctx , id )
342- if err != nil {
336+ if _ , err := r .tasks .Get (ctx , id ); err != nil {
343337 // Task was never started or was already successfully deleted
344338 return
345339 }
346- if err := r .cleanupAfterDeadShim (ctx , bundle , ns , id , pid ); err != nil {
340+
341+ if err := r .cleanupAfterDeadShim (ctx , bundle , ns , id ); err != nil {
347342 log .G (ctx ).WithError (err ).WithField ("bundle" , bundle .path ).
348343 Error ("cleaning up after dead shim" )
349344 }
@@ -353,7 +348,7 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
353348 "id" : id ,
354349 "namespace" : ns ,
355350 }).Error ("connecting to shim" )
356- err := r .cleanupAfterDeadShim (ctx , bundle , ns , id , pid )
351+ err := r .cleanupAfterDeadShim (ctx , bundle , ns , id )
357352 if err != nil {
358353 log .G (ctx ).WithError (err ).WithField ("bundle" , bundle .path ).
359354 Error ("cleaning up after dead shim" )
@@ -395,7 +390,13 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
395390 return o , nil
396391}
397392
398- func (r * Runtime ) cleanupAfterDeadShim (ctx context.Context , bundle * bundle , ns , id string , pid int ) error {
393+ func (r * Runtime ) cleanupAfterDeadShim (ctx context.Context , bundle * bundle , ns , id string ) error {
394+ log .G (ctx ).WithFields (logrus.Fields {
395+ "id" : id ,
396+ "namespace" : ns ,
397+ }).Warn ("cleaning up after shim dead" )
398+
399+ pid , _ := runc .ReadPidFile (filepath .Join (bundle .path , proc .InitPidFile ))
399400 ctx = namespaces .WithNamespace (ctx , ns )
400401 if err := r .terminate (ctx , bundle , ns , id ); err != nil {
401402 if r .config .ShimDebug {
@@ -418,6 +419,10 @@ func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns,
418419 if err := bundle .Delete (); err != nil {
419420 log .G (ctx ).WithError (err ).Error ("delete bundle" )
420421 }
422+ // kill shim
423+ if shimPid , err := runc .ReadPidFile (filepath .Join (bundle .path , "shim.pid" )); err == nil && shimPid > 0 {
424+ unix .Kill (shimPid , unix .SIGKILL )
425+ }
421426
422427 r .events .Publish (ctx , runtime .TaskDeleteEventTopic , & eventstypes.TaskDelete {
423428 ContainerID : id ,
0 commit comments