Repository navigation
Description
systemd version the issue has been seen with
253.5
Used distribution
Arch Linux (rolling)
Linux kernel version used
6.3.5-arch1-1
CPU architectures issue was seen on
x86_64
Component
systemd
Expected behaviour you didn't see
In its default configuration, libvirtd.service starts a libvirtd process that times out after 120 seconds of inactivity (no running domains and no connected clients). The service remains active and libvirtd is respawned on-demand via systemd socket activation (libvirtd-ro.socket, libvirtd.socket and libvirtd-admin.socket correspond to /var/lib/libvirt/{libvirt-sock-ro,libvirt-sock,libvirt-admin-sock}` respectively by default).
Unexpected behaviour you saw
After updating from systemd 253.4 to 253.5, socket activation stopped working. Attempting to connect to libvirtd via a socket after it times out yields nothing. Client software (I'm using virsh and virt-manager on the same host) halts indefinitely as soon as a libvirtd-dependent command is issued, and no errors are reported or logged before or after they are terminated (e.g. with Ctrl+C), including by systemd.
If systemctl restart libvirtd.service is issued in a separate terminal, libvirtd starts as normal and any processes trying to connect via a socket succeed immediately (there is no need to cancel the attempt and try again).
After rolling back systemd, libvirt and other updates installed at the same time in various combinations, the culprit appears to be systemd 253.5. Downgrading to 253.4 restores the desired behaviour.
Steps to reproduce the problem
- Install a libvirt package with stock systemd unit files
- Start libvirtd and/or enable its sockets as needed
- Wait for the libvirtd process to terminate after 2 minutes
- Run
sudo virsh listor similar - Wait indefinitely
Additional program output to the terminal or log subsystem illustrating the issue
Here's output from strace, in the absence of anything appearing in a log entry:
https://gist.github.com/lkrms/5bb9ef2e7ad8aa5d89e164b6e3f4d4a6#file-gistfile1-txt
Activity
poettering commentedon Jun 7, 2023
This is not a useful bug report. Always provide debug logs that show what's going on, i.e. "systemd-analyze log-level debug" and then reproduce the issue and provide what the service manager (i.e. pid1) logged as result of the activation request.
what makes you think this is a systemd issue? where's this tracked at libvirt project?
poettering commentedon Jun 7, 2023
Uh, stable dot releases are not tracked in this repo, that's a systemd-stable git repo thing.
Can you reproduce this on current git main?
Toolybird commentedon Jun 7, 2023
Bisected to ff32060 (Confirmed. Reverting this single commit makes it work.)
Not sure why this causes it... I haven't tried current git main yet...
Upstream libvirt issue here [1], but I believe it's barking up the wrong tree and contains misinformation (including from me).
libvirt daemons are documented here [2]. I am using the libvirt monolithic daemon.
[1] https://gitlab.com/libvirt/libvirt/-/issues/483
[2] https://libvirt.org/daemons.html
Toolybird commentedon Jun 7, 2023
BTW, when libvirtd is working properly, this is often found in the journal which could well be related (it's been like this for years IIRC):
the dnsmasq processes are definitely still running when the libvirtd.service shuts down...
berrange commentedon Jun 8, 2023
Libvirt intentionally leaves various things running when it shuts down, because it needs to be able to stop & start (for software upgrades) without disrupting running guests. Hence it sets
KillMode=process(as opposd tocgroup)poettering commentedon Jun 8, 2023
if libvirt watns to leave stuff running, it should probably move that stuff to a distinct scope (or service), so that it is unaffected by libvirt restarts.
Toolybird commentedon Jun 9, 2023
Fedora Rawhide also impacted:
https://bugzilla.redhat.com/show_bug.cgi?id=2213660
/cc @msekletar
MichaelRiss commentedon Jun 9, 2023
What is the intended behavior of systemd? When is systemd supposed to change the status of a service from "Active" to "Inactive"?
Is it
A: when the process with the Main PID exits?
or
B: when all processes in the CGroup have exited?
The commit ff32060 seems to flip the behavior from A to B. As libvirt depends on behavior A it worked so far and now as the behavior has changed to B libvirt fails. So the question for me here is: Is behavior B intended? If yes, then libvirt needs to be adapted. If not, it's a systemd bug.
MrDisguised commentedon Jun 10, 2023
Hi guys!! To temporarily fix the issue follow the guide that I have mentioned in the arch forum - https://bbs.archlinux.org/viewtopic.php?pid=2104316#p2104316
poettering commentedon Jun 12, 2023
This depends on ExitType=. It should be when the main process goes down (ExitType=main, the deault), or when the last process in the service's cgroup goes down (ExitType=cgroup).
I don't follow here. Can you explain why reseting the PID known state will make this behave like ExitType=cgroup?
MichaelRiss commentedon Jun 12, 2023
Thanks for the explanation (I'm not too familiar with systemd). Good that it can be configured with
ExitType=and by default it should do what libvirt expects. But why doesn't it do it all of a sudden? And no, I cannot explain why this one commit changed this behavior, I went with the bisection search result of @Toolybird . I can only wildly guess that when the main pid is set to unknown, determining whether the service is still active based on the main pid is not possible anymore, but this would need to be confirmed with a dive into the source code.msekletar commentedon Jun 13, 2023
Maybe we should add check for exit type in
service_good(). Hence we wouldn't make decisions about state transitions based on cgroup state for services which haveExitType=main. Also, we might want to renameservice_good()to something more descriptive.msizanoen1 commentedon Jun 13, 2023
@poettering Setting
main_pid_knowntofalsewill causemain_pid_goodto return-EAGAIN:systemd/src/core/service.c
Lines 1847 to 1861 in 768fcd7
which causes
service_goodto erroneously fall back tocgroup_good:systemd/src/core/service.c
Lines 2223 to 2233 in 768fcd7
effectively causing it to behave like
ExitType=cgroupinstead.As can be seen in
main_pid_goodit seems like the way it is intended to be is for themain_pidto be set to0whenSIGCHLDis received whilemain_pid_knownremainstrue.core/service: don't make state transitions based on cgroup state when…
Toolybird commentedon Jun 14, 2023
Just tested PR #28035 and can confirm it makes libvirt happy again. Thanks!
gdamjan commentedon Jun 16, 2023
a simple test case would be this:
after the main bash process exits with
0, the background child is not killed.ps.
bash -c "nohup sleep infinity & exit 1"on the other hand, fails the service AND kills the child processes too.berrange commentedon Jun 19, 2023
Yes, I don't disagree there - it would be a good idea if libvirt got its on-demand launched dnsmasq to be a (transient) systemd unit. We just had never considered that a priority thing, as we mostly thought the ExitType=main setting was intended to be compatible with leaving the process running when switching over from sysv-init originally & it had worked until now.
Add workaround for libvirt stuck issue for CRC
test: add coverage for systemd#27953
Merge pull request #28835 from mrc0mmand/more-tests
iamwo0 commentedon Mar 15, 2025
I'm useing ubuntu 24.04 desktop, and I'm trying to start libvirtd, but it auto turn inactive after 2 minutes. I'v run
journalctl -u libvirtd.service -band got logs like this:I don't know what can I do now, please help me. TKS!
jcpvdm commentedon Mar 15, 2025
@iamwo0, That looks like expected behavior. by default
libvirtdprocess times out (exit) after 120 seconds of inactivity (assuming there are no running domains and no connected clients), and this causeslibvirtd.serviceto change state to inactive.libvirtd.serviceis reactivated automatically by the socket (e.g. by runningvirsh list).Are you facing any problem due to
libvirtd.servicechanging to inactive?berrange commentedon Mar 17, 2025
@iamwo0 if you currently have problems with libvirtd please file them on libvirt's bug tracker (https://gitlab.com/libvirt/libvirt/-/issues/) rather than systemd's, as it is highly unlikely to be related to this old systemd issue. Further, as a general rule it is better to file new bugs, instead of commenting on bugs that were closed a long time ago.