Skip to content

Commit 7396ca9

Browse files
runc delete: do not ignore error from destroy
If container.Destroy() has failed, runc destroy still return 0, which is wrong and can result in other issues down the line. Let's always return error from destroy in runc delete. For runc checkpoint and runc run, we still treat it as a warning. Co-authored-by: Zhang Tianyang <[email protected]> Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent d3d7f7d commit 7396ca9

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

checkpoint.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ checkpointed.`,
7070
err = container.Checkpoint(options)
7171
if err == nil && !(options.LeaveRunning || options.PreDump) {
7272
// Destroy the container unless we tell CRIU to keep it.
73-
destroy(container)
73+
if err := container.Destroy(); err != nil {
74+
logrus.Warn(err)
75+
}
7476
}
7577
return err
7678
},

delete.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ func killContainer(container *libcontainer.Container) error {
1818
for i := 0; i < 100; i++ {
1919
time.Sleep(100 * time.Millisecond)
2020
if err := container.Signal(unix.Signal(0)); err != nil {
21-
destroy(container)
22-
return nil
21+
return container.Destroy()
2322
}
2423
}
2524
return errors.New("container init still running")
@@ -80,13 +79,11 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
8079
}
8180
switch s {
8281
case libcontainer.Stopped:
83-
destroy(container)
82+
return container.Destroy()
8483
case libcontainer.Created:
8584
return killContainer(container)
8685
default:
8786
return fmt.Errorf("cannot delete container %s that is not stopped: %s", id, s)
8887
}
89-
90-
return nil
9188
},
9289
}

libcontainer/container_linux.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,10 @@ func (c *Container) newInitConfig(process *Process) *initConfig {
874874
func (c *Container) Destroy() error {
875875
c.m.Lock()
876876
defer c.m.Unlock()
877-
return c.state.destroy()
877+
if err := c.state.destroy(); err != nil {
878+
return fmt.Errorf("unable to destroy container: %w", err)
879+
}
880+
return nil
878881
}
879882

880883
// Pause pauses the container, if its state is RUNNING or CREATED, changing

utils_linux.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,6 @@ func newProcess(p specs.Process) (*libcontainer.Process, error) {
8888
return lp, nil
8989
}
9090

91-
func destroy(container *libcontainer.Container) {
92-
if err := container.Destroy(); err != nil {
93-
logrus.Error(err)
94-
}
95-
}
96-
9791
// setupIO modifies the given process config according to the options.
9892
func setupIO(process *libcontainer.Process, rootuid, rootgid int, createTTY, detach bool, sockpath string) (*tty, error) {
9993
if createTTY {
@@ -303,7 +297,9 @@ func (r *runner) run(config *specs.Process) (int, error) {
303297

304298
func (r *runner) destroy() {
305299
if r.shouldDestroy {
306-
destroy(r.container)
300+
if err := r.container.Destroy(); err != nil {
301+
logrus.Warn(err)
302+
}
307303
}
308304
}
309305

0 commit comments

Comments
 (0)