cgroup pids controller kills systemd service?

From: Han Pingtian
Date: Thu Mar 17 2016 - 06:27:05 EST


Hi,

I noticed that if a systemd service forks children fiercely, then the whole
service will be terminated, perhaps by the kernel. Is this designed?

I have this reproducer:

$ cat reproducer/reproducer.service
[Unit]
Description=Reproducer of bz 136929
After=multi-user.target

[Service]
ExecStart=/home/hpt/reproducer/reproducer.sh
Type=forking

[Install]
WantedBy=multi-user.target

% cat reproducer/reproducer.sh
#!/bin/bash

foo()
{
echo $1: $(date)
sleep 30
}

bar()
{
c=1
while true
do
for ((i=1;i<=2048;i++))
do
foo $c &
((c++))
done

wait
c=1
done
}

# main
bar &

disown -a

exit 0

The default task limit of systemd is 512. Soon after the starting of the
service, it failed with those messages:

% sudo systemctl status reproducer.service 4:02 hpt@pinelp3 ~ %
â reproducer.service - Reproducer of bz 136929
Loaded: loaded (/etc/systemd/system/reproducer.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2016-03-17 04:02:09 CDT; 13s ago
Process: 14859 ExecStart=/home/hpt/reproducer/reproducer.sh (code=exited, status=0/SUCCESS)
Main PID: 14861 (code=exited, status=254)

Mar 17 04:02:07 pinelp3 reproducer.sh[14859]: /home/hpt/reproducer/reproducer.sh: fork: Resource temporarily unavailable
Mar 17 04:02:07 pinelp3 reproducer.sh[14859]: /home/hpt/reproducer/reproducer.sh: fork: Resource temporarily unavailable
Mar 17 04:02:07 pinelp3 reproducer.sh[14859]: /home/hpt/reproducer/reproducer.sh: fork: Resource temporarily unavailable
Mar 17 04:02:08 pinelp3 reproducer.sh[14859]: /home/hpt/reproducer/reproducer.sh: fork: Resource temporarily unavailable
Mar 17 04:02:08 pinelp3 reproducer.sh[14859]: /home/hpt/reproducer/reproducer.sh: fork: Resource temporarily unavailable
Mar 17 04:02:08 pinelp3 reproducer.sh[14859]: /home/hpt/reproducer/reproducer.sh: fork: Resource temporarily unavailable
Mar 17 04:02:08 pinelp3 systemd[1]: reproducer.service: Main process exited, code=exited, status=254/n/a
Mar 17 04:02:09 pinelp3 systemd[1]: reproducer.service: Unit entered failed state.
Mar 17 04:02:09 pinelp3 systemd[1]: reproducer.service: Failed with result 'exit-code'.
Mar 17 04:02:18 pinelp3 systemd[1]: Stopped Reproducer of bz 136929


Thanks in advance.