Skip to content

Don't error out when deleting parent cgroup dirs #11933

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

evanphx
Copy link
Contributor

@evanphx evanphx commented Jul 16, 2025

The current logic says "if we created a cgroup directory, we remove it". But the flaw in that logic is that if you run in
/sys/fs/cgroup/ns1/container1 you'll end up creating ns1 and container1. But if another container launches as /sys/fs/cgroup/ns1/container2, now while the first run created ns1, it can't delete it because container2 is in there.

The best fix I can think of, other than changing the logic full scale, is to just allow for a removal error on all but the top Own'd directory.

@EtiennePerot
Copy link
Collaborator

Idea seems fine, but please direct changes to the master branch.

@evanphx
Copy link
Contributor Author

evanphx commented Jul 16, 2025

@EtiennePerot No problem.

@evanphx evanphx changed the base branch from go to master July 16, 2025 23:47
The current logic says "if we created a cgroup directory, we remove it".
But the flaw in that logic is that if you run in
/sys/fs/cgroup/ns1/container1 you'll end up creating ns1 and container1.
But if another container launches as /sys/fs/cgroup/ns1/container2, now
while the first run created ns1, it can't delete it because container2
is in there.

The best fix I can think of, other than changing the logic full scale,
is to just allow for a removal error on all but the top Own'd directory.
@evanphx evanphx force-pushed the evanphx/uninstall-cgroup-soft branch from 458805d to 1a33662 Compare July 16, 2025 23:52
@avagin
Copy link
Collaborator

avagin commented Jul 22, 2025

The current logic says "if we created a cgroup directory, we remove it". But the flaw in that logic is that if you run in /sys/fs/cgroup/ns1/container1 you'll end up creating ns1 and container1. But if another container launches as /sys/fs/cgroup/ns1/container2, now while the first run created ns1, it can't delete it because container2 is in there.

The best fix I can think of, other than changing the logic full scale, is to just allow for a removal error on all but the top Own'd directory.

I think we should only remove the container cgroup. All parent cgroups should remain untouched; otherwise, it could race with the creation of other containers.

-------------------------------------------------------------------------------------
ct2                                                      | ct1
-------------------------------------------------------------------------------------
access(/sys/fs/cgroup/ns1) = 0          |
                                                           | rmdir(/sys/fs/cgroup/ns1)
mkdir(/sys/fs/cgroup/ns1/container2) |
-------------------------------------------------------------------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants