After an upgrade of `xdg-desktop-portal/bullseye-backports` (which
needrestart didn't detect should be restarted, BTW:
tconnors 4388 0.0 0.0 617848 5372 ? Sl 2021 2:14 /usr/libexec/xdg-desktop-portal
tconnors 4396 0.0 0.0 602912 2396 ? Sl 2021 0:31 /usr/libexec/xdg-document-portal
root 4405 0.0 0.0 2572 1684 ? Ss 2021 0:00 \_ fusermount -o rw,nosuid,nodev,fsname=portal,auto_unmount,subtype=portal -- /run/user/738/doc
tconnors 4411 0.0 0.0 529116 27656 ? Sl 2021 8:13 /usr/libexec/xdg-desktop-portal-gtk
)
I was wondering why needrestart was taking even longer than usual. So
I ran a few 'ps axfu' and discovered it was continually restarting
dpkg-query --search /bin/dash over and over again:
root 1130884 1.3 0.3 137036 123668 pts/125 S+ 12:41 0:04 | | \_ apt install xdg-desktop-portal/bullseye-backports
root 1131701 0.0 0.0 137036 32332 pts/125 S+ 12:41 0:00 | | \_ apt install xdg-desktop-portal/bullseye-backports
root 1141619 0.0 0.0 2424 596 pts/125 S+ 12:41 0:00 | | \_ sh -c test -x /usr/lib/needrestart/apt-pinvoke && /usr/lib/needrestart/apt-pinvoke || true
root 1141622 0.3 0.0 29212 23020 pts/125 S+ 12:41 0:01 | | \_ /usr/bin/perl -w /usr/share/debconf/frontend /usr/sbin/needrestart
root 1141782 14.3 0.2 83300 77220 pts/125 S+ 12:42 0:45 | | \_ /usr/bin/perl /usr/sbin/needrestart
root 1152868 1.0 0.0 12052 6076 pts/125 S+ 12:47 0:00 | | \_ /usr/bin/perl /etc/needrestart/hook.d/10-dpkg /bin/dash
root 1152870 99.0 0.3 134264 129920 pts/125 R+ 12:47 0:00 | | \_ dpkg-query --search /bin/dash
With /etc/needrestart/hook.d/10-dpkg and dpkg-query --search /bin/dash
constantly recycling PIDs (but /usr/sbin/needrestart remaining at the
root of the process tree the whole time).
After a while, it finally moved onto /bin/bash, and then eventually
finished. Since every time I looked, it was executing `dpkg-query
--search`, which takes 3 seconds when the filesystem cache is warm on
my system, it seems those results should be cached in the
/usr/sbin/needrestart process and 10-dpkg hook not asked to keep
reprocessing the same file, since they're obviously not able to change
when you're at the final step of a dpkg run with the dpkg lock held.