Bug 2215925 - Services configured with Delegate=yes and having a ExecStartPost/ExecStopPost command fail
Summary: Services configured with Delegate=yes and having a ExecStartPost/ExecStopPost...
Keywords:
Status: POST
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: systemd
Version: 8.8
Hardware: All
OS: Linux
high
high
Target Milestone: rc
: ---
Assignee: David Tardon
QA Contact: Frantisek Sumsal
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-06-19 12:30 UTC by Renaud Métrich
Modified: 2023-07-13 11:10 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github redhat-plumbers systemd-rhel8 pull 397 0 None open When Delegate=yes is set for a unit, run ExecStartPre= and friends in a subcgroup of the unit 2023-06-20 08:10:15 UTC
Github systemd systemd pull 10813 0 None Merged make sure ExecStartPre= and Delegate=yes mix well 2023-06-20 07:10:18 UTC
Red Hat Issue Tracker RHELPLAN-160194 0 None None None 2023-06-19 12:32:51 UTC

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)
  [...]


Note You need to log in before you can comment on or make changes to this bug.