** Description changed:

  [ Impact ]
  
  On Noble, systemd 255 can treat a stopped service as active when it
  still has saved file descriptors (dead-resources-pinned with
  FileDescriptorStorePreserve=yes). systemd can refuse to reopen the
  socket, or a connection to a socket left open can fail to start the
  service.
  
  In the authd migration tests, upgrading from the stable PPA left
  authd.socket and authd.service stopped:
  https://github.com/canonical/authd/issues/2317
  
  The authd packaging patch (https://github.com/canonical/authd/pull/2318)
  keeps the socket open during upgrades on Noble. Manual socket restarts
  can still fail.
  
  [ Test Plan ]
  
  Run this on a Noble VM. Noble's default journald unit does not set
  FileDescriptorStorePreserve=yes, so the test uses a service that keeps a
  descriptor after stopping.
  
  ```bash
  sudo bash <<'SRU'
  set -eu
  cd /run/systemd/system
  work=$(mktemp -d /run/sru-fdstore-XXXXXX)
  unit=${work##*/}
  trap 'systemctl stop "$unit."{socket,service,target} || :
-       rm -f -- "$unit."{socket,service,target}; systemctl daemon-reload; rm 
-r -- "$work"' EXIT
+       rm -f -- "$unit."{socket,service,target}; systemctl daemon-reload; rm 
-r -- "$work"' EXIT
  
  printf '[Socket]\nListenStream=%s/listener\n' "$work" >"$unit.socket"
  # Keep the stopped service loaded after the socket closes.
  printf '[Unit]\nWants=%s.service\n' "$unit" >"$unit.target"
  cat >"$unit.service" <<'UNIT'
  [Service]
  Type=notify
  NotifyAccess=all
  FileDescriptorStoreMax=1
  FileDescriptorStorePreserve=yes
  TimeoutStartSec=10
  # This status is set only if systemd returns the saved descriptor.
  ExecStart=:/bin/bash -ec '\
-     if [[ :$LISTEN_FDNAMES: == *:saved:* ]]; then systemd-notify --ready 
--status=restored; \
-     else systemd-notify --ready --fd=8 --fdname=saved 8</dev/null; fi; exec 
sleep infinity'
+     if [[ :$LISTEN_FDNAMES: == *:saved:* ]]; then systemd-notify --ready 
--status=restored; \
+     else systemd-notify --ready --fd=8 --fdname=saved 8</dev/null; fi; exec 
sleep infinity'
  UNIT
  
  systemctl daemon-reload
  systemctl start "$unit.socket" "$unit.target"
  failed=0
  for mode in reactivate reopen; do
-     # Close first so a queued connection cannot wake the service.
-     if [[ $mode == reopen ]]; then systemctl stop "$unit.socket"; fi
-     systemctl stop "$unit.service"
-     [[ $(systemctl show -P SubState "$unit.service") == dead-resources-pinned 
]]
-     [[ $(systemctl show -P NFileDescriptorStore "$unit.service") == 1 ]]
-     if { [[ $mode == reactivate ]] || systemctl start "$unit.socket"; } &&
-         timeout 5 python3 -c 'import socket, sys; 
socket.socket(socket.AF_UNIX).connect(sys.argv[1])' "$work/listener" &&
-         timeout 10 bash -c 'until [[ $(systemctl show -P StatusText "$1") == 
restored ]]; do sleep .2; done' _ "$unit.service" &&
-         systemctl is-active --quiet "$unit.service"; then
-         echo "PASS: $mode"
-     else
-         echo "FAIL: $mode"; failed=1
-     fi
+     # Close first so a queued connection cannot wake the service.
+     if [[ $mode == reopen ]]; then systemctl stop "$unit.socket"; fi
+     systemctl stop "$unit.service"
+     [[ $(systemctl show -P SubState "$unit.service") == dead-resources-pinned 
]]
+     [[ $(systemctl show -P NFileDescriptorStore "$unit.service") == 1 ]]
+     if { [[ $mode == reactivate ]] || systemctl start "$unit.socket"; } &&
+         timeout 5 python3 -c 'import socket, sys; 
socket.socket(socket.AF_UNIX).connect(sys.argv[1])' "$work/listener" &&
+         timeout 10 bash -c 'until [[ $(systemctl show -P StatusText "$1") == 
restored ]]; do sleep .2; done' _ "$unit.service" &&
+         systemctl is-active --quiet "$unit.service"; then
+         echo "PASS: $mode"
+     else
+         echo "FAIL: $mode"; failed=1
+     fi
  done
  
  # Only the patched run reaches the live-service rejection check.
  if (( failed == 0 )); then
-     if systemctl restart "$unit.socket"; then echo 'FAIL: live-service 
guard'; exit 1; fi
-     systemctl is-active --quiet "$unit.service"
+     if systemctl restart "$unit.socket"; then echo 'FAIL: live-service 
guard'; exit 1; fi
+     systemctl is-active --quiet "$unit.service"
  fi
  journalctl --sync
  journalctl --no-pager -b -u "$unit.socket" -o cat | grep -F 'already active, 
refusing'
  test "$failed" = 0
  echo 'PASS: live-service guard'
  SRU
  ```
  
  On stock Noble, reactivate times out and reopen logs "already active,
  refusing".
  
  Install the proposed package:
  sudo apt install -t noble-proposed systemd
  
  Reboot and repeat the test. Expect PASS: reactivate, PASS: reopen, and
  PASS: live-service guard.
  
  [ Where problems could occur ]
  
- If systemd let an Accept=no socket reopen while its service was running,
- clients could connect and get no reply. The service gets the listening
- socket at startup, so it would not receive the reopened one.
+ If systemd reopens an Accept=no socket while its service is still
+ running, new clients could connect but get no response: the service
+ still holds the old listening socket. The test checks that systemd still
+ refuses to reopen it.
  
  [ Other Info ]
  
  The fix shipped in systemd v257 and is already in Resolute, Stonking, and 
Tenacious.
  Upstream: https://github.com/systemd/systemd/pull/33874

** Bug watch added: github.com/canonical/authd/issues #2317
   https://github.com/canonical/authd/issues/2317

** Also affects: systemd via
   https://github.com/canonical/authd/issues/2317
   Importance: Unknown
       Status: Unknown

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2176110

Title:
  Noble: socket activation fails with a preserved fd store

To manage notifications about this bug go to:
https://bugs.launchpad.net/systemd/+bug/2176110/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to