`pasta` and `conmon` processes are sometimes left in calling process' control group
Container host Development machineSoftware versions
587980c
I have a web service (herein called deployer) which invokes Podman (using Node.js' child_process.spawnSync()) to create, start and stop containers. The deployer service is managed as a systemd unit.
Note that in control group paths, I've used /.../ as a shorthand for /sys/fs/cgroup/user.slice/user-33.slice/[email protected]/.
Problem: When I attempt to stop or restart the deployer service, systemd hangs while waiting for all remaining processes in the control group /.../app.slice/deployer.service to exit. This never happens, since the conmon and pasta processes created by Podman when deployer starts containers are left in the control group. conmon is not moved to its own libpod-conmon-<CONTAINER_ID>.scope control group as it usually is.
After 60 seconds, systemd kills the conmon and pasta processes, killing the containers they support. With --restart=always set on the containers, they are restarted. That said, no pasta process is created when restarting them, making the containerised application inaccessible over the network.
When running Podman in an SSH session, the pasta process lands in the control group /.../user.slice/podman-<PID>.scope and becomes a child of the system instance of systemd (PID 1). This allows the shell to exit without killing pasta or waiting for it to exit. That said, this transient control group is only supposed to live as long as the podman process does, but is kept alive by pasta.
In some cases—I forget exactly which—the user instance of systemd complains in the journal about "left-over process[es]":
Aug 11 02:20:15 <HOST> systemd[993]: podman.service: Found left-over process 3323 (pasta) in control group while starting unit. Ignoring.
Aug 11 02:20:15 <HOST> systemd[993]: podman.service: Found left-over process 3927 (pasta) in control group while starting unit. Ignoring.
Aug 11 02:20:15 <HOST> systemd[993]: podman.service: Found left-over process 24491 (pasta) in control group while starting unit. Ignoring.
Aug 11 02:20:20 <HOST> systemd[993]: podman.service: Unit process 3323 (pasta) remains running after unit stopped.
Aug 11 02:20:20 <HOST> systemd[993]: podman.service: Unit process 3927 (pasta) remains running after unit stopped.
Aug 11 02:20:20 <HOST> systemd[993]: podman.service: Unit process 24491 (pasta) remains running after unit stopped.
Possible fix: Explicitly move any spawned support processes (e.g., conmon, pasta, slirp4netns perhaps) to a dedicated control group like conmon sometimes is; libpod-support-<CONTAINER_ID>.scope may be a more accurate name.
I've tested several different methods of invoking Podman and recorded the parent processes and control groups of the spawned processes. I've left notes ("⚠️") wherever I think behaviour may not be correct.
-
Running Podman on development machine using remote system connection.
podman→ SSH connection →sshd-session→podman.socket→podman.service→ ...Details ⚠️
podman run \ --connection=foo \ --rm \ --detach \ --publish=1234:1234 \ alpine sleep 1000 podman run \ --connection=foo \ --rm \ --tty \ --interactive \ --publish=1234:1234 \ alpineProcess Parent process Control group podmansystemd(user instance)/.../app.slice/podman.service conmonsystemd(user instance)/.../user.slice/libpod-conmon-<CONTAINER_ID>.scope pastasystemd(user instance)/.../app.slice/podman.service
⚠️ Being daemonless, Podman's service unit should only live as long as thepodmanprocess.sleep/shconmon/.../user.slice/libpod-<CONTAINER_ID>.scope/container -
Running Podman on the host via SSH session.
Details ⚠️
podman run \ --rm \ --detach \ --publish=1234:1234 \ alpine sleep 1000 podman run \ --rm \ --tty \ --interactive \ --publish=1234:1234 \ alpineProcess Parent process Control group podmansshd-session→zsh/.../user.slice/podman-<PID>.scope conmonsystemd(PID 1)
⚠️ All other methods cause this process to be parented by the user instance of systemd, not PID 1./.../user.slice/libpod-conmon-<CONTAINER_ID>.scope pastasystemd(PID 1)
⚠️ See above./.../user.slice/podman-<PID>.scope
⚠️ Being transient, Podman's scope unit should only live as long as thepodmanprocess.sleep/shconmon/.../user.slice/libpod-<CONTAINER_ID>.scope/container -
Running Podman on the host from a user service (deployer).
Details ⚠️
podman run \ --rm \ --detach \ --publish=1234:1234 \ alpine sleep 1000Process Parent process Control group podmannode/.../app.slice/deployer.service conmonsystemd(user instance)/.../app.slice/deployer.service
⚠️ This process prevents the deployer service from being restarted without killing containers.pastasystemd(user instance)/.../app.slice/deployer.service
⚠️ See above.sleep/shconmon/.../user.slice/libpod-<CONTAINER_ID>.scope/container -
Running Podman with
--cgroup-parenton the host from a user service (deployer).⚠️ This option seems to have no effect, even with an explicit
--cgroupsoption. Is the example below incorrect?Details ⚠️
podman run \ --rm \ --detach \ --publish=1234:1234 \ --cgroups=enabled \ --cgroup-parent=user.slice \ alpine sleep 1000Process Parent process Control group podmannode/.../app.slice/deployer.service conmonsystemd(user instance)/.../app.slice/deployer.service
⚠️ This process prevents the deployer service from being restarted without killing containers.pastasystemd(user instance)/.../app.slice/deployer.service
⚠️ See above.sleep/shconmon/.../user.slice/libpod-<CONTAINER_ID>.scope/container -
Running Podman via
systemd-runon the host from a user service (deployer).This works but adds some complexity for the caller. deployer only requires this for calls to
podman start, not other invocations of Podman.Details ⚠️
systemd-run \ --user \ --scope \ --slice=user.slice \ --unit=podman.scope \ podman run \ --rm \ --detach \ --publish=1234:1234 \ alpine sleep 1000Process Parent process Control group podmannode/.../user.slice/podman.scope conmonsystemd(user instance)/.../user.slice/podman.scope
⚠️ This works, but differs from the intended control group for this process.pastasystemd(user instance)/.../user.slice/podman.scope
⚠️ See above.sleep/shconmon/.../user.slice/libpod-<CONTAINER_ID>.scope/container -
Running Podman with option
--cgroups=spliton the host from a user service (deployer).⚠️ This alters the control group hierarchy, but does not move support processes to a separate control group to that which the user service runs in. Each invocation of Podman creates a new "runtime" control group and moves the user service into it, eventually leading to an infinite stack of control groups, e.g., ...deployer.service/runtime/runtime/runtime/[...]/runtime
Details ⚠️
podman run \ --rm \ --detach \ --publish=1234:1234 \ --cgroups=split \ alpine sleep 1000Process Parent process Control group podmannode/.../app.slice/deployer.service conmonsystemd(user instance)/.../app.slice/deployer.service/runtime
⚠️ The parent control group is split, and this new "runtime" group is never removed. The user service is also moved to this new group and never moved back.pastasystemd(user instance)/.../app.slice/deployer.service/runtime
⚠️ See above.sleep/shconmon/.../app.slice/deployer.service/libpod-payload-<CONTAINER_ID>
The system states above were verified with these commands:
pstree --compact-not --hide-threads --show-pids --longpstree --compact-not --hide-threads --show-pids --long --show-parents <PID>systemctl --user statussystemctl --user status <PID>
In summary:
- Methods 1 and 2 probably should have the same result, but do not.
- Methods 3 and 4 have the same result.
- Method 5 has allowed me to work around this issue.
/assign
The fix is minimal and targeted - if we simply removes the artificial barrier that was preventing conmon from being properly scoped when running under systemd. On a Linux system running under systemd, this would allow podman commands invoked from a user service to work correctly with restart/stop operations.
I took some time to work through the code and understand the issue.
I assumed you have the network mode pasta enabled. Could you verify this for one of the affected containers with:
podman inspect <container> --format '{{.HostConfig.NetworkMode}}'
Podman, conmon and pasta seem to have somewhat independent cgroup placement mechanisms.
pasta does not appear to have any explicit cgroup relocation, so it inherits Podman’s cgroup and remains there.
Podman moves itself to a user-systemd scope if it does not own its current cgroup. This explains why it moves when started outside the user systemd hierarchy, e.g. from an SSH session. The user-systemd cgroups are owned by the user, which maps to UID 0 inside Podman’s rootless user namespace.
conmon normally gets moved into a dedicated libpod-conmon-
RemoteURI() == "" && INVOCATION_ID != ""
This explains why conmon stays in deployer.service when Podman is invoked directly from that service, while it gets its own scope in the remote-connection case.
I am new to this codebase so I may have missed some things.
I checked some of the commits to understand the rationale behind the specific cgroup behaviour, but haven‘t finished this analysis yet. Till now it looks Like the implementations were driven independently from each other.
A possible Solution could be to unify the behaviour for systemd service managed podman by either moving all helper processes plus container to their own cgroup or leave them all under the systemd service‘ scope to share its lifecycle.
@devchris123 I appreciate your thorough assessment. You are correct – there is no cgroup relocation in pasta, which is why I've included that in my second update. I checked the container utilizes pasta network type. Your assessment aligns with what I discovered:
- conmon – The RemoteURI() == "" && INVOCATION_ID != " " condition helps prevent scope generation when Podman is operating locally in systemd. This means the flaw here is that conmon remains attached to the cgroup of the service.
- pasta – No cgroup relocation. It derives Podman's cgroup and does not leave it.
- Podman – Moves itself into a user-systemd scope provided it does not govern the cgroup.
My solution is in line with your initial recommendation: shift all helper processes into their own cgroup.
- conmon: the INVOCATION_ID check has been taken away so that it invariably uses libpod-conmon-.scope.
- pasta: utilized cgroups relocation in libpod-pasta-.scope (retaining the current rootless netns approach). This means that conmon and pasta will be able to endure service restarts and containers would keep working.
As for the second suggestion (to have everything within systemd service scope), it implies that this service cannot be restarted, thereby stopping containers altogether.
@TanayJalan I agree, that leaving leaving everything under systemd scope would still lead to the behaviour the user experiences.
I'm just thinking, that changing this to relocating pasta and conmon by default is technically a breaking change. There could be use cases, where this behaviour is actually desired and relied on. We can assume something triggered the remote uri and invocation ID additions to branch this behaviour.
A more defensive solution would be for example introducing a configuration to have conmon's and pasta's cgroups relocated in any case, but leave the current behaviour as default. Something like --separate-cgroups (just thinking out loud here). Downside is this makes the code more complex.
@devchris123 I get why you're worried about breaking changes. I think this is a bug fix, not a change in how things work:
- The way things work now was never meant to happen. We added the INVOCATION_ID check so systemd could deal with cgroups. It had an unexpected result. This kept conmon in the services cgroup. This was not what people wanted. It just worked because most people didn't restart systemd services while containers were running.
- Rootless netns pasta already works this way. The idea of moving pasta to its scope is already in vendor/go.podman.io/common/libnetwork/internal/rootlessnetns/netns_linux.go:203-246. We're just using the idea for per-container pasta.
- The called "breaking change" is actually fixing a bug. If someone was depending on conmon/pasta being killed when the service restarts they were depending on a mistake. The right way is for these processes to keep running through service restarts, which --restart=always is supposed to do.
- Adding a flag makes things more complicated for no reason. A --separate-cgroups flag would force users to know about and pick this behavior. Most users don't know that conmon/pasta stay, in the services cgroup until the containers stop. Moving these processes to their own scopes by default, like rootless netns does, is the right fix.
@TanayJalan yes, that sounds reasonable, if you are sure about the unintended side effect of the added INVOCATION_ID id and the use of systemd with podman in general. Looking forward to see, what the reviewers say.
This problem can actually kill your containers, assuming the conmon holds pipes for stdout/stderr.
Now, let's say you have Golang code:
log.Printf(...)
you trying to write to non existing pipe reader -> go program is like: not gonna do this. Bye bye. (SIGPIPE)
@Spectrik—are you seeing containers crash while conmon is still running or only after? In my experience, containers are killed as soon as the support processes are, as opposed to when they first attempt to log to standard output.
As for moving forward, I'd like to wait for a project maintainer to take a look at this, but that may take some time. In the meantime, the workaround using systemd-run that I mentioned in the original issue is working for me.
This problem can actually kill your containers, assuming the conmon holds pipes for stdout/stderr.
Now, let's say you have Golang code:
log.Printf(...)you trying to write to non existing pipe reader -> go program is like: not gonna do this. Bye bye. (SIGPIPE)
@Spectrik You're right - this is a real problem. When systemd's stop timeout hits (60s), it kills conmon and pasta in the service cgroup, which kills the containers. With --restart=always, they restart, but the pasta process is gone so the container is unreachable over the network.
The fix I'm working on moves conmon and pasta to their own scopes (libpod-conmon-
i'm also waiting for the maintainers to review this. until then, the discussion remains open.
I defer to @giuseppe on the exact cgroup setup but running podman as child of another service running under systemd is certainly unexpected design wise and as such breaks the assumptions. I would say the helper processes (i.e. the PER CONTAINER pasta process) should all be part of the same cgroup as conmon. If conmon dies so should they. Conmon should be part of a unit if it is the main process but it should be moved elsewhere if we are just some child under it I suppose, though this part is not clear. I could see cases for people wanting conmon and thus the container to exit when the service exits.
If --restart=always does not restart the network processes than that is a bug, there was no version information provided but I am pretty sure it should do that already.
have you considered using --cgroups=split if you are already running inside a systemd scope?
@Luap99—Do you think executing Podman from another program is unusual? Should Compose cover these use-cases? I built the deployer service to listen for webhook events—hence a web service—but there may be a better approach. At the moment, the systemd-run workaround is good enough for me.
I tested method 3 (invoking Podman in a user service) again today. When the user service is stopped with systemctl, the node process of the service and the pasta process of a started container both exit. The container's conmon process ignores SIGTERM, though, but can be killed with kill -9 <PID>. Once the last process in the control group exits, the service becomes "stopped". Manually killing either the conmon or pasta process does not automatically kill the other.
My original report may have been wrong. In my testing today, when stopping a service created with the --restart=always option, the containerised process survives the stopping of the user service.
-
systemd appears to send
SIGTERMorSIGHUPto each process in the service's control group. As above,nodeandpastaprocesses exit, but theconmonprocess does not. -
After some delay, systemd sends
SIGKILLto theconmonprocess and stops the service. -
The containerised process stays running, re-parented by the user-instance
systemdprocess and remaining in its separate libpod-<CONTAINER_ID>.scope control group.podman container lsshows the container as "up", despite bothconmonandpastaprocesses having been killed. Stopping the container shows an error but does stop the containerised process.Error: container <CONTAINER_ID> conmon exited prematurely, exit code could not be retrieved: conmon process killed
-
The container is not started again, even though
podman stopwas just invoked. Which program should handle container restart policy?
Software versions were included at the top of the original issue, but were collapsed:
Container host
- Podman: 5.8.3
- conmon: 2.1.12
- pasta: commit
587980c- systemd: 257.13
- Running rootless
Development machine
- Podman: 5.8.3
It's a Debian 13 machine—some of the version combinations may be unusual. I installed Podman from the Forky (testing) repository.
@giuseppe—Thanks for the suggestion. I just tested again using the --cgroups=split option. This does change behaviour, but still doesn't break out of the control group that the calling service is in. Podman now moves the node process (the deployer service) into a new "runtime" control group where the conmon and pasta processes are spawned. This means that the container support processes are still descendants of the deployer service's control group, which is the original problem.
I've added the test results to the original issue and copied them below. I also tried this with the --cgroup-parent option, but that combination is not allowed.
Running Podman with option
--cgroups=spliton the host from a user service (deployer).⚠️ This alters the control group hierarchy, but does not move support processes to a separate control group to that which the user service runs in. Each invocation of Podman creates a new "runtime" control group and moves the user service into it, eventually leading to an infinite stack of control groups, e.g., ...deployer.service/runtime/runtime/runtime/[...]/runtime
podman run \ --rm \ --detach \ --publish=1234:1234 \ --cgroups=split \ alpine sleep 1000
Process Parent process Control group podmannode/.../app.slice/deployer.service conmonsystemd(user instance)/.../app.slice/deployer.service/runtime
⚠️ The parent control group is split, and this new "runtime" group is never removed. The user service is also moved to this new group and never moved back.pastasystemd(user instance)/.../app.slice/deployer.service/runtime
⚠️ See above.sleep/shconmon/.../app.slice/deployer.service/libpod-payload-<CONTAINER_ID>
That's a lot to read, but there are so many permutations to test. Thanks again!
if you need a more specific control, couldn't you move the processes under /runtime to the target cgroup you'd like?
Using the --cgroups=split option, I would need to manually move three processes:
- Since the
nodeprocess is mistakenly moved into the new control group (/.../app.slice/deployer.service/runtime), it would need to be moved back to the service unit's control group (/.../app.slice/deployer.service). - The
conmonandpastaprocesses would need to be moved from the new "runtime" control group to a new group dedicated to a particular container's support processes (e.g., /.../machine.slice/libpod-support-<CONTAINER_ID>.scope).
Starting another container afterwards could also fail when Podman tries to create a new "runtime" control group, since the old "runtime" control group may still exist.
Manually moving processes between control groups also isn't right, though, and systemd expects to be the only party managing its unit control groups. Units with the Delegate property enabled are expected to manage their own subtrees, but Podman isn't a unit. The systemd-run workaround avoids manually moving processes around and effectively forces Podman to behave as I think it should by default.
For what it's worth, I think of Podman as a management program that is separate from its spawned processes. If Podman or its calling process crashes, containers should not be killed (or half-killed), just as an SSH connection being dropped shouldn't shut down the remote machine. Without passing explicit command-line options that change the default behaviour and regardless of Podman is spawned in the process and control group hierarchies, I think new container processes should always land in a predictable place in the those two hierarchies. Currently, there's a lot of variation in where these processes land between the six methods of invoking Podman listed in the original issue.
you can't move them back. cgroup v2 does not allow processes in non-leaf cgroups, that is why /runtime is created and populated.
If you want a new cgroup to be created and all the processes moved there, just combine it with systemd-run --scope --user -p Delegate=true.
Manually moving processes between control groups also isn't right, though, and systemd expects to be the only party managing its unit control groups. Units with the
Delegateproperty enabled are expected to manage their own subtrees, but Podman isn't a unit. Thesystemd-runworkaround avoids manually moving processes around and effectively forces Podman to behave as I think it should by default.
It is fine if you specify Delegate
@mnrx @giuseppe Thanks for the continued feedback on #29582.
The fix in this branch (a4464f5933) specifically addresses the pasta process being left in the service's control group when running podman from a systemd user service. It moves per-container pasta processes into a dedicated libpod-pasta-
Regarding --cgroups=split: as you noted, this creates a new "runtime" control group that's never cleaned up, leading to an infinite stack of groups. The current fix takes a different approach—relocating only the pasta process to its own scope without altering the user service's cgroup hierarchy.
The conmon process handling is tracked separately; the current change focuses on pasta. You can test the fix with: podman run --rm --detach --publish=1234:1234 alpine sleep 1000
then restart the systemd service and verify pasta is in its own scope
Looking forward to your testing feedback.
I am not sure though that is what we want to do by default. Creating a scope has its cost and for most users it doesn't matter. If you want full control, you've already the possibility using --cgroups=split
@giuseppe Thanks for the feedback. You're right that scope creation has overhead - but the issue is specifically about systemd user services where pasta processes prevent service restart/kill. The default behavior was never intended to leave pasta in the parent service's cgroup. For users not running under systemd user services, the impact is minimal. The --cgroups=split option remains available for those who need fine-grained control. This fix targets the specific regression for systemd user service users without adding overhead for everyone else.
how do you decide if the new scope must be created or not?