From 9726f56fdc8e6b3beb55d21d121ca08c941acb10 Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Wed, 1 Jun 2022 13:14:20 -0700 Subject: [PATCH 1/2] runtime: force stop container after the container process exits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set thestop container force flag to true so that the container state is always set to “StateStopped” after the container wait goroutine is finished. This is necessary for the following delete container step to succeed. Fixes: #4359 Signed-off-by: Feng Wang --- src/runtime/pkg/containerd-shim-v2/wait.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/pkg/containerd-shim-v2/wait.go b/src/runtime/pkg/containerd-shim-v2/wait.go index 0f6c4fe066..5e86149c1a 100644 --- a/src/runtime/pkg/containerd-shim-v2/wait.go +++ b/src/runtime/pkg/containerd-shim-v2/wait.go @@ -78,7 +78,7 @@ func wait(ctx context.Context, s *service, c *container, execID string) (int32, shimLog.WithField("sandbox", s.sandbox.ID()).Error("failed to delete sandbox") } } else { - if _, err = s.sandbox.StopContainer(ctx, c.id, false); err != nil { + if _, err = s.sandbox.StopContainer(ctx, c.id, true); err != nil { shimLog.WithError(err).WithField("container", c.id).Warn("stop container failed") } } From 9d27c1fced805981a6327a539006a266291d4b31 Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Wed, 1 Jun 2022 17:38:28 -0700 Subject: [PATCH 2/2] agent: ignore ESRCH error when destroying containers destroy() method should ignore the ESRCH error from signal::kill and continue the operation as ESRCH is often considered harmless. Fixes: #4359 Signed-off-by: Feng Wang --- src/agent/rustjail/src/container.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/agent/rustjail/src/container.rs b/src/agent/rustjail/src/container.rs index 88c058868a..a1207104fc 100644 --- a/src/agent/rustjail/src/container.rs +++ b/src/agent/rustjail/src/container.rs @@ -1063,7 +1063,19 @@ impl BaseContainer for LinuxContainer { let st = self.oci_state()?; for pid in self.processes.keys() { - signal::kill(Pid::from_raw(*pid), Some(Signal::SIGKILL))?; + match signal::kill(Pid::from_raw(*pid), Some(Signal::SIGKILL)) { + Err(Errno::ESRCH) => { + info!( + self.logger, + "kill encounters ESRCH, pid: {}, container: {}", + pid, + self.id.clone() + ); + continue; + } + Err(err) => return Err(anyhow!(err)), + Ok(_) => continue, + } } if spec.hooks.is_some() {