-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libpod: drop hack to set conmon cgroup pids.max=1 #13403
Closed
+25
−29
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
package libpod | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"strings" | ||
"time" | ||
|
||
"github.com/containers/common/pkg/cgroups" | ||
"github.com/containers/common/pkg/config" | ||
"github.com/containers/podman/v4/libpod/define" | ||
"github.com/containers/podman/v4/libpod/events" | ||
"github.com/containers/podman/v4/pkg/rootless" | ||
"github.com/containers/podman/v4/pkg/specgen" | ||
spec "github.com/opencontainers/runtime-spec/specs-go" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
@@ -195,10 +197,15 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool, | |
// Go through and lock all containers so we can operate on them all at | ||
// once. | ||
// First loop also checks that we are ready to go ahead and remove. | ||
containersLocked := true | ||
for _, ctr := range ctrs { | ||
ctrLock := ctr.lock | ||
ctrLock.Lock() | ||
defer ctrLock.Unlock() | ||
defer func() { | ||
if containersLocked { | ||
ctrLock.Unlock() | ||
} | ||
}() | ||
|
||
// If we're force-removing, no need to check status. | ||
if force { | ||
|
@@ -216,32 +223,6 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool, | |
} | ||
} | ||
|
||
// We're going to be removing containers. | ||
// If we are Cgroupfs cgroup driver, to avoid races, we need to hit | ||
// the pod and conmon Cgroups with a PID limit to prevent them from | ||
// spawning any further processes (particularly cleanup processes) which | ||
// would prevent removing the Cgroups. | ||
if p.runtime.config.Engine.CgroupManager == config.CgroupfsCgroupsManager { | ||
// Get the conmon Cgroup | ||
conmonCgroupPath := filepath.Join(p.state.CgroupPath, "conmon") | ||
conmonCgroup, err := cgroups.Load(conmonCgroupPath) | ||
if err != nil && err != cgroups.ErrCgroupDeleted && err != cgroups.ErrCgroupV1Rootless { | ||
logrus.Errorf("Retrieving pod %s conmon cgroup %s: %v", p.ID(), conmonCgroupPath, err) | ||
} | ||
|
||
// New resource limits | ||
resLimits := new(spec.LinuxResources) | ||
resLimits.Pids = new(spec.LinuxPids) | ||
resLimits.Pids.Limit = 1 // Inhibit forks with very low pids limit | ||
|
||
// Don't try if we failed to retrieve the cgroup | ||
if err == nil { | ||
if err := conmonCgroup.Update(resLimits); err != nil { | ||
logrus.Warnf("Error updating pod %s conmon cgroup PID limit: %v", p.ID(), err) | ||
} | ||
} | ||
} | ||
|
||
var removalErr error | ||
|
||
ctrNamedVolumes := make(map[string]*ContainerNamedVolume) | ||
|
@@ -300,6 +281,12 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool, | |
} | ||
} | ||
|
||
// let's unlock the containers so the cleanup processes can terminate their execution | ||
for _, ctr := range ctrs { | ||
ctr.lock.Unlock() | ||
} | ||
containersLocked = false | ||
|
||
// Remove pod cgroup, if present | ||
if p.state.CgroupPath != "" { | ||
logrus.Debugf("Removing pod cgroup %s", p.state.CgroupPath) | ||
|
@@ -328,7 +315,16 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool, | |
} | ||
} | ||
if err == nil { | ||
if err := conmonCgroup.Delete(); err != nil { | ||
for attempts := 0; attempts < 50; attempts++ { | ||
err = conmonCgroup.Delete() | ||
if err == nil || os.IsNotExist(err) { | ||
// success | ||
err = nil | ||
break | ||
} | ||
time.Sleep(time.Millisecond * 100) | ||
} | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any use to having at least a logdebug here if attempts are >= 50 just stating that we ran out of attempts? |
||
if removalErr == nil { | ||
removalErr = errors.Wrapf(err, "error removing pod %s conmon cgroup", p.ID()) | ||
} else { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small concern here, we are unlocking
containers
before remove is completed so otherpodman
process have permission to modify containers and lock containers in apod
while the actualpod
is being removed from another process.However I'm unable to think of issues where this race could impact anybody.