From df5322b6ec677608c5c60fa032017ca1faed906e Mon Sep 17 00:00:00 2001 From: guocanfeng Date: Tue, 7 Jun 2022 14:10:50 +0800 Subject: [PATCH] add wait check for task.kill(syscall.sigquit) --- pkg/runtime/containerd/client.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/runtime/containerd/client.go b/pkg/runtime/containerd/client.go index c8b28e111..391c21749 100644 --- a/pkg/runtime/containerd/client.go +++ b/pkg/runtime/containerd/client.go @@ -706,9 +706,15 @@ func (cc *ctdClient) StopContainer(container string, timeout *time.Duration) (er } // After sending the signal, start the timer to force-kill the task - timeoutC := make(chan error) + timeoutC := make(<-chan containerd.ExitStatus) timer := time.AfterFunc(*timeout, func() { - timeoutC <- task.Kill(cc.ctx, syscall.SIGQUIT) + timeoutC, err = task.Wait(cc.ctx) + if err != nil { + return + } + if err = task.Kill(cc.ctx, syscall.SIGQUIT); err != nil { + return + } }) // Wait for the task to stop or the timer to fire @@ -716,7 +722,7 @@ func (cc *ctdClient) StopContainer(container string, timeout *time.Duration) (er case exitStatus := <-waitC: timer.Stop() // Cancel the force-kill timer err = exitStatus.Error() // TODO: Handle exit code - case err = <-timeoutC: // The kill timer has fired + case <-timeoutC: // The kill timer has fired } // Delete the task