From 65d5a2b68b52817a1cb1a6d9da5d3ee7fb3e26a3 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Tue, 14 Dec 2021 15:29:07 +0100 Subject: [PATCH] pause scope: don't use the global math/rand RNG Otherwise, we'll always get the same sequence of random numbers which may lead to conflicts. Also bump the number of maximum attempts to 10 instead of 3. [NO NEW TESTS NEEDED] as I cannot enforce random number collisions. Existing tests should continue be green and flake slightly less. Signed-off-by: Valentin Rothberg --- utils/utils.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 095370a086..241e361cda 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -11,6 +11,7 @@ import ( "strconv" "strings" "sync" + "time" "github.com/containers/common/pkg/cgroups" "github.com/containers/podman/v3/libpod/define" @@ -204,8 +205,9 @@ func moveProcessToScope(pidPath, slice, scope string) error { func MovePauseProcessToScope(pausePidPath string) { var err error - for i := 0; i < 3; i++ { - r := rand.Int() + state := rand.New(rand.NewSource(time.Now().UnixNano())) + for i := 0; i < 10; i++ { + r := state.Int() err = moveProcessToScope(pausePidPath, "user.slice", fmt.Sprintf("podman-pause-%d.scope", r)) if err == nil { return