Skip to content

Commit

Permalink
fix post stop hook not always called successfully
Browse files Browse the repository at this point in the history
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 <fshb1988@gmail.com>
  • Loading branch information
abel-von committed Aug 2, 2024
1 parent ad5b481 commit 5aab881
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions libcontainer/state_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5aab881

Please sign in to comment.