Skip to content

cgroupv2: fix Poststop hooks could not run when using systemd driver#2329

Closed
lifubang wants to merge 1 commit intoopencontainers:masterfrom
lifubang:systemd
Closed

cgroupv2: fix Poststop hooks could not run when using systemd driver#2329
lifubang wants to merge 1 commit intoopencontainers:masterfrom
lifubang:systemd

Conversation

@lifubang
Copy link
Copy Markdown
Member

How to reproduce:

[root@localhost systemdtest]# runc --systemd-cgroup run -d test
[root@localhost systemdtest]# runc --systemd-cgroup delete -f test
ERRO[0000] cannot detect unified path

The error is in here:

func runPoststopHooks(c *linuxContainer) error {
if c.config.Hooks != nil {
s, err := c.currentOCIState()
if err != nil {
return err
}
for _, hook := range c.config.Hooks.Poststop {
if err := hook.Run(s); err != nil {
return err
}
}
}
return nil
}

If we got an error, the Poststop hooks could not run because the func has returned.

The reason is here:

func RemovePaths(paths map[string]string) (err error) {
delay := 10 * time.Millisecond
for i := 0; i < 5; i++ {
if i != 0 {
time.Sleep(delay)
delay *= 2
}
for s, p := range paths {
os.RemoveAll(p)
// TODO: here probably should be logging
_, err := os.Stat(p)
// We need this strange way of checking cgroups existence because
// RemoveAll almost always returns error, even on already removed
// cgroups
if os.IsNotExist(err) {
delete(paths, s)
}
}
if len(paths) == 0 {
return nil
}
}
return fmt.Errorf("Failed to remove paths: %v", paths)
}

Because we delete the cgroup paths value in cgroup manager when destroy.

Signed-off-by: lifubang lifubang@acmcoder.com

Signed-off-by: lifubang <lifubang@acmcoder.com>
return err
unitName := getUnitName(m.Cgroups)
statusChan := make(chan string, 1)
if _, err := dbusConnection.StopUnit(unitName, "replace", statusChan); err == nil {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kolyshkin
I think we may not need StopUnit method. Because if the init process has been exited, the cgroup path will be deleted by systemd automatically.
WDYT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I think it is still needed, otherwise it will show up in systemctl output as "killed" or something like that (I haven't checked yet, just a hunch).

We can also take a look at crun implementation -- in there the unit is removed from systemd first, then killed. Might make more sense.

@kolyshkin
Copy link
Copy Markdown
Contributor

@lifubang can you please rebase it? (libcontainer/cgroups/systemd/unified_hierarchy.go is renamed to libcontainer/cgroups/systemd/v2.go)

@lifubang
Copy link
Copy Markdown
Member Author

ERRO[0000] cannot detect unified path
This error has been fixed by #2299 .
I will add waiting for StopUnit in #2331 .

@lifubang lifubang closed this Apr 21, 2020
@lifubang lifubang deleted the systemd branch May 28, 2020 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants