From 0364aef1e07c2d70c1fc03029bb11c2012e5b166 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 20 Apr 2023 10:16:36 +0200 Subject: [PATCH] test: fix race when listing cgroups A cgroup could have been deleted by the time WalkDir is trying to access it. Ignore the error and continue. Closes: https://github.com/containers/podman/issues/17989 Signed-off-by: Giuseppe Scrivano --- test/e2e/pod_rm_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/e2e/pod_rm_test.go b/test/e2e/pod_rm_test.go index 1cd2291cca..a46f29eb36 100644 --- a/test/e2e/pod_rm_test.go +++ b/test/e2e/pod_rm_test.go @@ -1,6 +1,7 @@ package integration import ( + "errors" "fmt" "io/fs" "os" @@ -47,11 +48,13 @@ var _ = Describe("Podman pod rm", func() { // Also check that we don't leak cgroups err := filepath.WalkDir("/sys/fs/cgroup", func(path string, d fs.DirEntry, err error) error { if err != nil { + // A cgroup directory could have been deleted in the meanwhile filepath.WalkDir was + // accessing it. If that happens, we just ignore the error. + if d.IsDir() && errors.Is(err, os.ErrNotExist) { + return nil + } return err } - if !d.IsDir() { - Expect(err).ToNot(HaveOccurred()) - } if strings.Contains(d.Name(), podid) { return fmt.Errorf("leaking cgroup path %s", path) }