lxd icon indicating copy to clipboard operation
lxd copied to clipboard

Changing `limits.cpu` of a container can be racy

Open simondeziel opened this issue 2 years ago • 1 comments

In tests/cgroup from lxd-ci.git, the following sometimes fail when unsetting the limits.cpu and immediately checking if the limit is gone:

echo "==> Testing CPU limits"
lxc config set c1 limits.cpu=2
[ "$(lxc exec c1 -- nproc)" = "2" ]

lxc config set c1 limits.cpu=200
[ "$(lxc exec c1 -- nproc)" = "$(nproc)" ]

lxc config set c1 limits.cpu=0,2
[ "$(lxc exec c1 -- nproc)" = "2" ]

lxc config set c1 limits.cpu=2-2
[ "$(lxc exec c1 -- nproc)" = "1" ]

lxc config unset c1 limits.cpu
[ "$(lxc exec c1 -- nproc)" = "$(nproc)" ]

If a sleep 2 is introduced between the last 2 lines, the race is avoided.

Additional information:

# snap list lxd
Name  Version      Rev    Tracking     Publisher   Notes
lxd   git-7294d23  26547  latest/edge  canonical✓  -

simondeziel avatar Dec 12 '23 01:12 simondeziel

So the application of the limit is still always taking effect, its just that there can be a short delay between the set/unset command returning and the limit actually being applied.

tomponline avatar Dec 15 '23 08:12 tomponline