Skip to content

cgroup: destroy the cgroup if its setup fails - #2242

Merged
giuseppe merged 1 commit into
containers:mainfrom
kolyshkin:cgroup-destroy-on-failure
Sep 11, 2026
Merged

giuseppe merged 1 commit into
containers:mainfrom
kolyshkin:cgroup-destroy-on-failure

Conversation

@kolyshkin

Copy link
Copy Markdown
Collaborator

If libcrun_cgroup_enter fails after the cgroup has been created (e.g. setting a resource limit fails because of an invalid value), it returns an error without the cgroup status, so the caller has nothing to destroy and the cgroup is left behind.

For example, crun run with an invalid CPU period correctly fails, but leaves an empty cgroup, which in turn makes it impossible to remove its parent.

Destroy the cgroup in such case. If the cgroup creation itself fails, it is not destroyed, as it might be pre-existing.

Found by the "set cpu period with no quota (invalid period)" runc integration test (see #2238), with a check added to runc tests that the container cgroup is removed (opencontainers/runc#5455).

If libcrun_cgroup_enter fails after the cgroup has been created (e.g.
setting a resource limit fails because of an invalid value), it returns
an error without the cgroup status, so the caller has nothing to destroy
and the cgroup is left behind.

For example, "crun run" with an invalid CPU period correctly fails, but
leaves an empty cgroup, which in turn makes it impossible to remove its
parent.

Destroy the cgroup in such case. If the cgroup creation itself fails, it
is not destroyed, as it might be pre-existing.

Found by the "set cpu period with no quota (invalid period)" runc
integration test.

Signed-off-by: Kir Kolyshkin <[email protected]>

@giuseppe giuseppe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@giuseppe
giuseppe merged commit d37c983 into containers:main Sep 11, 2026
59 checks passed
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.

2 participants