Skip to content

Commit

Permalink
utils: use podman-pause-$RANDOM.scope name
Browse files Browse the repository at this point in the history
[Backport of containers#12323 into v3.4, to fix gating-test flakes]

we try hard to re-use the existing podman-pause.scope name when it
already exists, causing any sort of race errors when the already
existing scope is terminating.

There is no such a requirement though, so just try with a random
name.

Closes: containers#12065

[NO NEW TESTS NEEDED] it fixes a race in the CI

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe authored and edsantiago committed Nov 22, 2021
1 parent 36b6bf1 commit 2d265da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 11 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"os/exec"
"strconv"
Expand Down Expand Up @@ -203,7 +204,16 @@ func moveProcessToScope(pidPath, slice, scope string) error {
// MovePauseProcessToScope moves the pause process used for rootless mode to keep the namespaces alive to
// a separate scope.
func MovePauseProcessToScope(pausePidPath string) {
err := moveProcessToScope(pausePidPath, "user.slice", "podman-pause.scope")
var err error

for i := 0; i < 3; i++ {
r := rand.Int()
err = moveProcessToScope(pausePidPath, "user.slice", fmt.Sprintf("podman-pause-%d.scope", r))
if err == nil {
return
}
}

if err != nil {
unified, err2 := cgroups.IsCgroup2UnifiedMode()
if err2 != nil {
Expand Down
9 changes: 0 additions & 9 deletions utils/utils_supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ func RunUnderSystemdScope(pid int, slice string, unitName string) error {
ch := make(chan string)
_, err = conn.StartTransientUnit(unitName, "replace", properties, ch)
if err != nil {
// On errors check if the cgroup already exists, if it does move the process there
if props, err := conn.GetUnitTypeProperties(unitName, "Scope"); err == nil {
if cgroup, ok := props["ControlGroup"].(string); ok && cgroup != "" {
if err := moveUnderCgroup(cgroup, "", []uint32{uint32(pid)}); err == nil {
return nil
}
// On errors return the original error message we got from StartTransientUnit.
}
}
return err
}

Expand Down

0 comments on commit 2d265da

Please sign in to comment.