From 575bba953c095fe5ca852d449afd76700ce34ea1 Mon Sep 17 00:00:00 2001 From: lifubang Date: Tue, 10 Oct 2023 11:34:09 +0800 Subject: [PATCH] never ignore cgroup destroy error for runc-delete Signed-off-by: lifubang --- checkpoint.go | 4 +++- delete.go | 7 ++----- libcontainer/state_linux.go | 3 +++ utils_linux.go | 10 +++++----- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/checkpoint.go b/checkpoint.go index a8a27f248bc..f49b346dbf6 100644 --- a/checkpoint.go +++ b/checkpoint.go @@ -70,7 +70,9 @@ checkpointed.`, err = container.Checkpoint(options) if err == nil && !(options.LeaveRunning || options.PreDump) { // Destroy the container unless we tell CRIU to keep it. - destroy(container) + if err := destroy(container); err != nil { + logrus.Warn(err) + } } return err }, diff --git a/delete.go b/delete.go index 682101ccad8..38c6f88200e 100644 --- a/delete.go +++ b/delete.go @@ -18,8 +18,7 @@ func killContainer(container *libcontainer.Container) error { for i := 0; i < 100; i++ { time.Sleep(100 * time.Millisecond) if err := container.Signal(unix.Signal(0)); err != nil { - destroy(container) - return nil + return destroy(container) } } return errors.New("container init still running") @@ -72,7 +71,7 @@ status of "ubuntu01" as "stopped" the following will delete resources held for } switch s { case libcontainer.Stopped: - destroy(container) + return destroy(container) case libcontainer.Created: return killContainer(container) default: @@ -81,7 +80,5 @@ status of "ubuntu01" as "stopped" the following will delete resources held for } return fmt.Errorf("cannot delete container %s that is not stopped: %s", id, s) } - - return nil }, } diff --git a/libcontainer/state_linux.go b/libcontainer/state_linux.go index 8d8f31d3678..aa406767126 100644 --- a/libcontainer/state_linux.go +++ b/libcontainer/state_linux.go @@ -36,6 +36,9 @@ type containerState interface { func destroy(c *Container) error { err := c.cgroupManager.Destroy() + if err != nil { + return err + } if c.intelRdtManager != nil { if ierr := c.intelRdtManager.Destroy(); err == nil { err = ierr diff --git a/utils_linux.go b/utils_linux.go index 0f787cb3387..14ab69b955b 100644 --- a/utils_linux.go +++ b/utils_linux.go @@ -82,10 +82,8 @@ func newProcess(p specs.Process) (*libcontainer.Process, error) { return lp, nil } -func destroy(container *libcontainer.Container) { - if err := container.Destroy(); err != nil { - logrus.Error(err) - } +func destroy(container *libcontainer.Container) error { + return container.Destroy() } // setupIO modifies the given process config according to the options. @@ -289,7 +287,9 @@ func (r *runner) run(config *specs.Process) (int, error) { func (r *runner) destroy() { if r.shouldDestroy { - destroy(r.container) + if err := destroy(r.container); err != nil { + logrus.Warn(err) + } } }