Skip to content

fix(core): treat a scope cgroup pruned during destroy as vacated - #192

Merged
ElbertePlinio merged 2 commits into
mainfrom
fix/cgroup-teardown-prune-window
Sep 23, 2026
Merged

ElbertePlinio merged 2 commits into
mainfrom
fix/cgroup-teardown-prune-window

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

Closes #190

destroyCgroupMembers checked that the scope directory existed, then guardCgroupKill ran statfs, read cgroup.procs and wrote cgroup.kill. A concurrent createContainmentScope in any other session prunes empty sibling scope cgroups, and a session that launched nothing has an empty scope, so the directory could vanish between those steps. Teardown then refused with "is not on a cgroup v2 filesystem", "could not read cgroup.procs" or "could not write cgroup.kill", left the session in error status, and failed the desktop integration test when Vitest workers ran other session-creating files in parallel.

A failed pre-kill check on a directory that existed when destroy began is now classified. If the directory is gone, the kernel only allowed that rmdir on an empty cgroup, so the scope is vacated and cleanup proceeds to the marker sweep with nothing killed. The entry can linger for under a millisecond while cgroup.procs already fails with ENODEV, so a still-visible directory gets a 100 ms bound to disappear; one that stays keeps its refusal. Ownership, evacuation and membership verification are unchanged and never decide "vacated" on their own.

Regressions in the simulated-cgroup suite: the three prune sites (statfs, cgroup.procs, cgroup.kill) each confirm cleanup with nothing killed and no signals; a lingering entry with ENODEV is waited out; a path that exists but reports a non-cgroup filesystem magic keeps its refusal. The real-filesystem test for a plain directory outside cgroupfs already existed.

Evidence on a delegated-cgroup host:

  • containment tests 54/54; the new prune-site tests fail on the unfixed source, the lingering test fails without the settle wait.
  • tsc, oxlint and complexity-gate (17 functions, 0 violations) clean.
  • Kernel probe over 3000 concurrent rmdirs: cgroup.procs fails ENOENT or ENODEV; in 14 cases the entry was still visible right after, and in all cases gone within 1 ms.
  • The Investigate marker-containment escapee assertion blocking native cleanup CI #179 prune-race probe: unmodified main 104/291 unconfirmed in one run; this build 0/573 across two runs.
  • Full parallel vitest suite: 144 files, 1933 tests passed; packages/desktop-linux/test/integration.test.ts passed in it.

destroyCgroupMembers checked that the scope directory existed and then
guardCgroupKill ran statfs, read cgroup.procs and wrote cgroup.kill on it.
A concurrent createContainmentScope in another session prunes empty
sibling scope cgroups, and a session that launched nothing has an empty
scope, so the directory could vanish between those steps. Teardown then
refused with "is not on a cgroup v2 filesystem", "could not read
cgroup.procs" or "could not write cgroup.kill", left the session in
error status and failed the desktop integration test when Vitest workers
ran other session-creating files in parallel.

A failed pre-kill check on a directory that existed when destroy began is
now classified: if the directory is gone, the kernel only allowed that
rmdir on an empty cgroup, so the scope is vacated and cleanup proceeds to
the marker sweep with nothing killed. The entry can linger for under a
millisecond while cgroup.procs already fails with ENODEV, so it gets a
short bound to disappear; one that stays keeps its refusal. Ownership,
evacuation and membership verification are unchanged and never decide
"vacated" on their own.

The preserved prune-race probe from #179 produced the refusal in about a
third of empty-scope destroys on unmodified main and in none of 573 on
this build.

Closes #190
Review of the prune-window handling found two gaps. existsSync folds
every inspection error into false, so a populated scope whose parent
lost search permission after the initial existence check would have
been classified as vacated and cleanup confirmed by the marker sweep
alone. The absence probe now uses lstat and treats only ENOENT as gone;
any other error keeps the refusal. A statfs that succeeds and reports a
foreign filesystem is now a final refusal, even if that directory later
disappears; only a statfs that could not answer may be the prune window.

Regressions cover both, and the prune-site table gains the cgroup.procs
read inside membership verification.
@ElbertePlinio
ElbertePlinio force-pushed the fix/cgroup-teardown-prune-window branch from 1a0235a to 9dd41aa Compare September 23, 2026 16:03
@ElbertePlinio
ElbertePlinio merged commit 082cf22 into main Sep 23, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/cgroup-teardown-prune-window branch September 23, 2026 16:12
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.

Cgroup teardown refuses cleanup when a concurrent create prunes an empty scope cgroup

1 participant