Skip to content

Commit ee62711

Browse files
committed
utils: use podman-pause-$RANDOM.scope name
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]>
1 parent c661664 commit ee62711

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

Diff for: utils/utils.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"io/ioutil"
8+
"math/rand"
89
"os"
910
"os/exec"
1011
"strconv"
@@ -203,7 +204,16 @@ func moveProcessToScope(pidPath, slice, scope string) error {
203204
// MovePauseProcessToScope moves the pause process used for rootless mode to keep the namespaces alive to
204205
// a separate scope.
205206
func MovePauseProcessToScope(pausePidPath string) {
206-
err := moveProcessToScope(pausePidPath, "user.slice", "podman-pause.scope")
207+
var err error
208+
209+
for i := 0; i < 3; i++ {
210+
r := rand.Int()
211+
err = moveProcessToScope(pausePidPath, "user.slice", fmt.Sprintf("podman-pause-%d.scope", r))
212+
if err == nil {
213+
return
214+
}
215+
}
216+
207217
if err != nil {
208218
unified, err2 := cgroups.IsCgroup2UnifiedMode()
209219
if err2 != nil {

Diff for: utils/utils_supported.go

-9
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ func RunUnderSystemdScope(pid int, slice string, unitName string) error {
4444
ch := make(chan string)
4545
_, err = conn.StartTransientUnit(unitName, "replace", properties, ch)
4646
if err != nil {
47-
// On errors check if the cgroup already exists, if it does move the process there
48-
if props, err := conn.GetUnitTypeProperties(unitName, "Scope"); err == nil {
49-
if cgroup, ok := props["ControlGroup"].(string); ok && cgroup != "" {
50-
if err := moveUnderCgroup(cgroup, "", []uint32{uint32(pid)}); err == nil {
51-
return nil
52-
}
53-
// On errors return the original error message we got from StartTransientUnit.
54-
}
55-
}
5647
return err
5748
}
5849

0 commit comments

Comments
 (0)