Skip to content

Commit

Permalink
never ignore cgroup destroy error for runc-delete
Browse files Browse the repository at this point in the history
Signed-off-by: lifubang <[email protected]>
  • Loading branch information
lifubang committed Oct 10, 2023
1 parent 04fc3fe commit 48ff07c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 3 additions & 1 deletion checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
7 changes: 2 additions & 5 deletions delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand All @@ -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
},
}
3 changes: 3 additions & 0 deletions libcontainer/state_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 48ff07c

Please sign in to comment.