From 0d535f56e514b37a21aa5e70e2c1becba732f8f1 Mon Sep 17 00:00:00 2001 From: lifupan Date: Tue, 21 May 2019 16:53:43 +0800 Subject: [PATCH] shimv2: kill a container return directly once the container termianted According to CRI specs, kubelet will call StopPodSandbox() at least once before calling RemovePodSandbox, and this call is idempotent, and must not return an error if all relevant resources have already been reclaimed. And in that call it will send a SIGKILL signal first to try to stop the container, thus once the container has terminated, here should ignore this signal and return directly. Fixes:#1672 Signed-off-by: lifupan --- containerd-shim-v2/service.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/containerd-shim-v2/service.go b/containerd-shim-v2/service.go index d479790e1..782c4a87a 100644 --- a/containerd-shim-v2/service.go +++ b/containerd-shim-v2/service.go @@ -677,6 +677,20 @@ func (s *service) Kill(ctx context.Context, r *taskAPI.KillRequest) (_ *ptypes.E return nil, err } + // According to CRI specs, kubelet will call StopPodSandbox() + // at least once before calling RemovePodSandbox, and this call + // is idempotent, and must not return an error if all relevant + // resources have already been reclaimed. And in that call it will + // send a SIGKILL signal first to try to stop the container, thus + // once the container has terminated, here should ignore this signal + // and return directly. + if signum == syscall.SIGKILL || signum == syscall.SIGTERM { + if c.status == task.StatusStopped { + logrus.WithField("sandbox", s.sandbox.ID()).WithField("Container", c.id).Debug("Container has already been stopped") + return empty, nil + } + } + processID := c.id if r.ExecID != "" { execs, err := c.getExec(r.ExecID)