Skip to content

Commit b7f2dab

Browse files
committed
fix post stop hook not always called successfully
If the first time post stop hook called with a failure(maybe because some resources is not ready to be recycled), the second retry of `runc delete` will return directly because the container root directoy is already removed. so that the post stop hook is not called.
1 parent 459ce2f commit b7f2dab

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

libcontainer/state_linux.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ func destroy(c *Container) error {
5454
return fmt.Errorf("unable to remove container's IntelRDT group: %w", err)
5555
}
5656
}
57+
c.initProcess = nil
58+
if err := runPoststopHooks(c); err != nil {
59+
return fmt.Errorf("unable to run post stop hooks: %w", err)
60+
}
61+
c.state = &stoppedState{c: c}
62+
5763
if err := os.RemoveAll(c.stateDir); err != nil {
5864
return fmt.Errorf("unable to remove container state dir: %w", err)
5965
}
60-
c.initProcess = nil
61-
err := runPoststopHooks(c)
62-
c.state = &stoppedState{c: c}
63-
return err
66+
return nil
6467
}
6568

6669
func runPoststopHooks(c *Container) error {

0 commit comments

Comments
 (0)