Comment 34 for bug 1357252

Revision history for this message
James Hunt (jamesodhunt) wrote :

From @teds findings:

"The Upstart job creates the cgroup as it goes through each phase in the job, but it sets the cgroup to be destroyed when all of its PIDs are gone. When starting the second or later task (what ever that might be, seems to be post-stop a lot though) there is then a race between starting that task and the cgroup being destroyed if all of the PIDs in the group have exited with the main job. On entering the function to create the task the group is created, and if right then cgmanager realizes the PIDs are gone it deletes it before the new PID can be added."

The solution is to not mark created cgroups 'remove-on-empty' immediately after they are created, but instead to request cgmanager mops up the cgroups after the last job processes cgroups have been created.

Note that this approach works correctly for system jobs which specify the cgroup stanza. However, it is not currently reliable for session jobs since because logind does not clean up cgroups itself, systemd-shim arranges for this to happen on behalf of the users session by marking the logind-created cgroups 'remove-on-empty' and letting cgmanager clean up.... which brings us back to the problem which the upstart changes are designed to fix.

So, further works is required to resolve this problem by enhancing systemd-shim to implement 'abandoncgroup' and 'stopsession' so that logind works as expected.