podman icon indicating copy to clipboard operation
podman copied to clipboard

rootless: RunUnderSystemdScope waits forever on the StartTransientUnit job channel when the systemd manager never completes the job

Open tomcruiseqi opened this issue 3 months ago • 3 comments

What happened?

Every rootless podman command can hang forever, with no output and no error, when the systemd manager never completes the transient-unit job that RunUnderSystemdScope waits for.

RunUnderSystemdScope ends with:

	ch := make(chan string)
	_, err = conn.StartTransientUnitContext(context.Background(), unitName, "replace", properties, ch)
	if err != nil { ... }

	// Block until job is started
	<-ch

	return nil

The <-ch read has no timeout and does not honor the context. For rootless callers the connection goes to the user manager (cgroups.UserConnection); if that manager accepts the StartTransientUnit call but the job is never removed (wedged user manager, job queued behind a never-completing job, a lost JobRemoved signal), the read blocks for eternity. The scope move is best-effort cgroup hygiene on the startup path of every rootless podman command (SetupRootless → MovePauseProcessToScope, and the euid == 0 branch for the re-exec'd process), so a wedged manager turns into "every rootless podman invocation silently hangs until killed" — and because failures in this helper are only logged at debug level, there is no diagnostic output at all.

This is not hypothetical: on GitHub-hosted ubuntu-24.04 runners, a rootless podman info probe run as a non-login system user (uid 999, linger enabled, cgroup v2 delegation healthy) hung until killed (exit 124) on 11 consecutive CI dispatches, reproducible on every attempt within one runner instance. The podman debug log always ends at

time="..." level=info msg="Setting parallel job count to 7"

which is printed immediately before SetupRootless reaches the scope-move path — nothing further is ever printed. (For completeness: in our case the stall finally turned out to be compounded by a separate problem — a lock region left by a different podman version shadowing the distro binary; but the unbounded systemd wait below is real and was separately reproduced.)

A minimal demonstration of the failure class: run any rootless podman command with the user's systemd manager unresponsive (kill -STOP $(systemctl show -p MainPID --value user@$(id -u).service)), and the command hangs until externally killed. Pointing DBUS_SESSION_BUS_ADDRESS / DBUS_SYSTEM_BUS_ADDRESS at a dead socket so the connection fails fast makes the hang unreachable — which is how we currently work around it in CI, and rootless containers (pull, build, podman run --network pasta) keep working with the scope move degraded, so treating this call as truly best-effort is safe.

Expected behavior

The wait for the job should be bounded and cancellable — e.g. select on the channel, ctx.Done() and a timeout — degrading to a debug-logged failure like the other error paths of this helper, instead of wedging the whole command.

Environment

  • Present in podman 5.8.4 via go.podman.io/common (pkg/systemd/systemd_linux.go:104-152 in the vendored module)
  • Present in podman 4.9.x (utils/utils_supported.go:59-60) — the version shipped in Ubuntu 24.04, where we hit it
  • Ubuntu 24.04, cgroup v2, systemd 255, rootless

tomcruiseqi avatar Sep 03 '26 10:09 tomcruiseqi

/assign

devchris123 avatar Sep 11 '26 07:09 devchris123

I opened a PR in container-libs to address this issue. https://github.com/podman-container-tools/container-libs/pull/1168 is ready for review now.

A default timeout is added to the existing API for moving the scope and an additional API is created to pass podmans context to it. This must be done in a separate PR once the vendor code is updated.

devchris123 avatar Sep 14 '26 07:09 devchris123

A friendly reminder that this issue had no activity for 30 days.

github-actions[bot] avatar Oct 15 '26 01:10 github-actions[bot]