#591

Hard dependencies not honored during shutdown

OpenGaugeforeveropened 10d ago

Describe the bug

During system shutdown, dinit stops services before the services that hard-depend on them (depends-on). At runtime the same dependency is enforced correctly: dinitctl stop refuses to stop the dependency while the dependent is running. During shutdown rollback, the order is ignored.

In my case, automount (autofs, serving a CIFS share) has depends-on for both wpa_supplicant-nm and NetworkManager. At shutdown, both of those stop first, the network goes down, and automount can't unmount the share. It then hangs until its stop-timeout expires and dinit kills it. Other pairs show the same pattern, e.g. dbus stopping before its hard dependents NetworkManager and elogind.

Things I've ruled out:

  • No service uses kill-all-on-stop (grep of /etc/dinit.d and /usr/lib/dinit.d).
  • Same behaviour with loginctl poweroff and sudo dinitctl shutdown.
  • Happens with both dinit 0.22.0 and 0.22.1.
  • With the network up, dinitctl stop automount completes immediately. The service only hangs when its dependencies are stopped first.

To Reproduce

  1. Create /etc/dinit.d/wpa_supplicant-nm:
   type      = process
   command   = /usr/bin/wpa_supplicant -u -s -O /run/wpa_supplicant
   waits-for = dbus
   before    = NetworkManager
  1. Create /etc/dinit.d/automount:
   type         = process
   command      = /usr/bin/automount -f
   depends-on   = early-fs-local.target
   depends-on   = NetworkManager
   depends-on   = wpa_supplicant-nm
   stop-timeout = 10

/etc/dinit.d/NetworkManager (from the Artix package):

   type            = process
   command         = /usr/bin/NetworkManager -n
   smooth-recovery = true
   depends-on      = dbus
   depends-on      = pre-network.target
   before          = network.target
  1. Enable the services and reboot:
   dinitctl enable wpa_supplicant-nm
   dinitctl enable automount
  1. Confirm the dependency is active at runtime:
   $ sudo dinitctl stop wpa_supplicant-nm
   dinitctl: cannot stop service 'wpa_supplicant-nm' due to the following dependents:
   (only direct dependents are listed. Exercise caution before using '--force' !!)
     automount
  1. Shut down with sudo dinitctl shutdown or loginctl poweroff.

  2. The console shows:

   [STOPPD] wpa_supplicant-nm
   [STOPPD] NetworkManager

followed by a ~10 second pause, after which automount is killed for exceeding its stop time.

Expected behaviour

automount should stop first, while wpa_supplicant-nm and NetworkManager are still running. Only after automount has stopped should its dependencies be stopped. This matches the documented behaviour that a service process will not be signalled to terminate until its dependents have stopped.

Additional context

  • Distro: Artix Linux
  • dinit: 0.22.1 (dinit and dinit-base 0.22.1-1); also reproduced after downgrading to 0.22.0-3
  • Desktop: KDE Plasma with the ly display manager; turnstiled runs a user dinit instance
  • The share is CIFS, mounted by autofs through a direct map
  • Kernel 7.2.9-artix1-1

Activity

2
davmac3149d ago

Thanks for a thorough and detailed report. The fix was simple; it's a bit embarrassing that none of the tests caught the problem (I've added a test now that would do so).

Gaugeforever9d ago

Thank you for developing and maintaining open source software!