Skip to content

engine-dev: retry enabling cgroup controllers when a client connects during startup - #14975

Closed
sipsma wants to merge 1 commit into
mainfrom
sipsma/engine-cgroup-controllers-race
Closed

sipsma wants to merge 1 commit into
mainfrom
sipsma/engine-cgroup-controllers-race

Conversation

@sipsma

@sipsma sipsma commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

The engine's entrypoint moves every process out of the container's root cgroup, then enables the cgroup controllers for its children. A process that joins the root cgroup in between makes that write fail with EBUSY. A CLI connecting through docker exec while the engine starts does exactly that: runc puts the exec in the container's root cgroup. busybox sed, which did the write, exits 0 without a message when its write fails, so the engine started without the controllers.

From then on, every docker exec also landed in the root cgroup and kept it busy for the engine's whole life. crun, failing to enable the controllers at each container start, retried 1000 times with a 1 ms sleep: about 1.1 s per container. A cold build of dagger's CLI starts about 1,400 containers and took ~155 s instead of ~27 s. In our runs, this happened in between 1 in 200 and 6 in 100 cold starts, depending on the setup.

The entrypoint now retries the move and the write, as moby's dind and e2e/helm/k3s-entrypoint.sh do, with echo, which reports a failed write. After 10 attempts 0.1 s apart, it prints diagnostics and the engine exits. So if the controllers can never be enabled, the engine now fails to start instead of starting without them.

TestEngine/TestExecCgroupControllers gains a case that starts a process in the root cgroup right after the entrypoint first reads its processes, and keeps it there, as a connected client does. The case fails with the old entrypoint and passes with this one. In 200 cold starts alternating the two entrypoints, the first build took 26.40 s with the old one and 26.42 s with the new one. The new one retried once and succeeded on its second attempt. No run stalled.

@sipsma
sipsma force-pushed the sipsma/engine-cgroup-controllers-race branch from 067beb2 to ccbb61f Compare October 30, 2026 01:15
…e root

The entrypoint moves every process out of the root cgroup, then enables the
controllers for its children. A process that joins the root cgroup between
the two makes the write fail with EBUSY. A client connecting through
"docker exec" while the engine starts does exactly that: runc puts the exec
in the container's root cgroup while no controllers are enabled there. The
write was done by busybox sed, which exits 0 without a message when its
write fails, so the engine started without the controllers. Every later
"docker exec" then also landed in the root cgroup, keeping it busy for the
engine's whole life, and crun, failing to enable the controllers at each
container start, retried 1000 times with a 1 ms sleep: about a second per
container. A cold build of dagger's CLI took ~155 s instead of ~27 s.

Retry the move and the write, as e2e/helm/k3s-entrypoint.sh and moby's
dind do, with echo, which reports a failed write, and stop the engine with
diagnostics after 10 attempts.

TestEngine/TestExecCgroupControllers gains a case that starts a process in
the root cgroup right after the entrypoint's first read of its processes,
through a cat wrapper, and keeps it there, as a connected client's exec
stays.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma

sipsma commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Its commits moved into #15007, which now combines the engine's pending performance changes, to save CI runs.

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.

1 participant