Bug 2215925

Summary: Services configured with Delegate=yes and having a ExecStartPost/ExecStopPost command fail
Product: Red Hat Enterprise Linux 8 Reporter: Renaud Métrich <rmetrich>
Component: systemdAssignee: David Tardon <dtardon>
Status: CLOSED ERRATA QA Contact: Frantisek Sumsal <fsumsal>
Severity: high Docs Contact:
Priority: high    
Version: 8.8CC: dtardon, jamacku, rcarrier, systemd-maint-list, tpetr, trehiopa
Target Milestone: rcKeywords: Bugfix, Reproducer, Triaged
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: systemd-239-78.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-11-14 15:48:29 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Renaud Métrich 2023-06-19 12:30:18 UTC
Description of problem:

A customer reports that his service enabling Delegation (a podman container actually) cannot start properly because it has some ExecStartPost command.
This happens with cgroup unified hierarchy only.
Thanks to his reproducer (see below), I can confirm there is an issue due to having systemd start the ExecStartPost command to root's node, which is not possible and returns EBUSY.

It seems like we need to backport https://github.com/systemd/systemd/pull/10813/files which is related to issue https://github.com/systemd/systemd/issues/10482.

What is weird is that my own reproducer, not using podman but with just delegation and some child hierarchy, doesn't fail for me, so somehow podman must "protect" the hierarchy.

Version-Release number of selected component (if applicable):

systemd-239 up to systemd-239-74.el8_8 included

How reproducible:

Always

Steps to Reproduce:
1. Boot the system with "systemd.unified_cgroup_hierarchy=1"
2. Create a container service unit

  # cat /etc/containers/systemd/delegate_issue.container 
  [Unit]
  Description=The sleep container
  After=local-fs.target
  
  [Service]
  TimeoutStopSec=2
  
  [Container]
  Image=ubi8
  Exec=sleep 1000

3. Reload systemd so that service generation is performed and start then stop the service

  # yum -y install crun
  # systemctl daemon-reload
  # systemctl start delegate_issue.service
  # systemctl stop delegate_issue.service
  # systemctl status delegate_issue.service

Actual results:

● delegate_issue.service - The sleep container
   Loaded: loaded (/etc/containers/systemd/delegate_issue.container; generated)
   Active: failed (Result: timeout) since Mon 2023-06-19 12:53:58 CEST; 2s ago
  Process: 2243 ExecStopPost=/usr/bin/rm -f /run/delegate_issue.cid (code=exited, status=219/CGROUP)
  Process: 2242 ExecStopPost=/usr/bin/podman rm -f -i --cidfile=/run/delegate_issue.cid (code=exited, status=219/CGROUP)
  [...]

Expected results:

Execution of ExecStopPost commands and no failure with 219/CGROUP status

Additional info:

Stracing systemd shows EBUSY on PID 2242, then child of 2242 (2243) fails as well:

# grep -A2 "write(.*/sys/fs/cgroup/system.slice/delegate_issue.service/" /tmp/systemd.strace
[...]
1     12:53:58.754846 write(72</sys/fs/cgroup/system.slice/delegate_issue.service/cgroup.procs>, "2242\n", 5) = -1 EBUSY (Device or resource busy) <0.000006>
2243  12:53:58.764451 write(3</sys/fs/cgroup/system.slice/delegate_issue.service/cgroup.procs>, "2243\n", 5 <unfinished ...>
2243  12:53:58.764467 <... write resumed>) = -1 EBUSY (Device or resource busy) <0.000010>

Comment 1 David Tardon 2023-06-20 08:08:18 UTC
With the upstream fix:

# systemctl status delegate_issue.service
● delegate_issue.service
   Loaded: loaded (/etc/containers/systemd/delegate_issue.container; generated)
   Active: failed (Result: timeout) since Tue 2023-06-20 10:03:43 CEST; 41s ago
  Process: 5435 ExecStopPost=/usr/bin/rm -f /run/delegate_issue.cid (code=exited, status=0/SUCCESS)
  Process: 5392 ExecStopPost=/usr/bin/podman rm -f -i --cidfile=/run/delegate_issue.cid (code=exited, status=0/SUCCESS)
  [...]

Comment 2 Plumber Bot 2023-08-22 11:35:56 UTC
fix merged to github main branch -> https://github.com/redhat-plumbers/systemd-rhel8/pull/397

Comment 7 errata-xmlrpc 2023-11-14 15:48:29 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (systemd bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:7097