From 5aab881fd3c10a7818fe87f452399488b918d9e4 Mon Sep 17 00:00:00 2001 From: Abel Feng Date: Thu, 1 Aug 2024 17:35:37 +0800 Subject: [PATCH] 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. Signed-off-by: Abel Feng --- libcontainer/state_linux.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libcontainer/state_linux.go b/libcontainer/state_linux.go index 0b1b8716a76..c891abaa5cf 100644 --- a/libcontainer/state_linux.go +++ b/libcontainer/state_linux.go @@ -54,13 +54,16 @@ func destroy(c *Container) error { return fmt.Errorf("unable to remove container's IntelRDT group: %w", err) } } + c.initProcess = nil + if err := runPoststopHooks(c); err != nil { + return fmt.Errorf("unable to run post stop hooks: %w", err) + } + c.state = &stoppedState{c: c} + if err := os.RemoveAll(c.stateDir); err != nil { return fmt.Errorf("unable to remove container state dir: %w", err) } - c.initProcess = nil - err := runPoststopHooks(c) - c.state = &stoppedState{c: c} - return err + return nil } func runPoststopHooks(c *Container) error {