Hi Stephen,

Stephen Rothwell <debb...@rothwell.id.au> writes:

> Services restarted by needrestart have a unexpected file descriptor
> open (on /usr/share/perl5/NeedRestart/UI/Debconf.pm).  Manually
> restarting the service gets rid of it.
>
> For example: lvcreate when used from a cron job after cron has been
> restarted by needrestart reports:
>
> File descriptor 4 (/usr/share/perl5/NeedRestart/UI/Debconf.pm) leaked
> on lvcreate invocation. Parent PID 9376: /bin/sh

I did some tests to find out why the FD is open:

- If the system runs systemd than this issue seems to be hidden since
  needrestart does not restart the service directly as on SysV.

- When starting needrestart it tries to detects possible frontend
  implementation. On Debian it will use Needrestart::UI::Debconf inside
  an eval block. The Debconf::Client perl module does a exec or fork (i
  did not look at it's source code) and restart needrestart again piped
  against the Debconf engine.

- Perl seems not to set O_CLOEXEC on the FD opened to read the package
  file inside of the eval block and so the FD is still open in the
  Debconf engine and in the respawned needrestart process.

- If SysV init is used than needrestart will call the init script and
  the orphaned FD to Debconf.pm is passed into the daemons.


# ps a | grep needrestart
13548 pts/8    S+     0:00 /usr/bin/perl -w /usr/share/debconf/frontend 
/usr/sbin/needrestart
13559 pts/8    S+     0:01 /usr/bin/perl /usr/sbin/needrestart


# ls -lha /proc/13548/fd
total 0
dr-x------ 2 root root  0 Jun  2 13:34 .
dr-xr-xr-x 9 root root  0 Jun  2 13:34 ..
lrwx------ 1 root root 64 Jun  2 13:34 1 -> /dev/pts/8
lrwx------ 1 root root 64 Jun  2 13:34 10 -> /dev/pts/8
lr-x------ 1 root root 64 Jun  2 13:34 11 -> pipe:[102655556]
lr-x------ 1 root root 64 Jun  2 13:34 13 -> pipe:[102655557]
lrwx------ 1 root root 64 Jun  2 13:34 2 -> /dev/pts/8
lrwx------ 1 root root 64 Jun  2 13:34 3 -> /dev/pts/8
lr-x------ 1 root root 64 Jun  2 13:34 4 -> 
/usr/share/perl5/NeedRestart/UI/Debconf.pm
lrwx------ 1 root root 64 Jun  2 13:34 5 -> /var/cache/debconf/config.dat
lrwx------ 1 root root 64 Jun  2 13:34 6 -> /var/cache/debconf/passwords.dat
lrwx------ 1 root root 64 Jun  2 13:34 7 -> /var/cache/debconf/templates.dat
l-wx------ 1 root root 64 Jun  2 13:34 8 -> pipe:[102655232]
lr-x------ 1 root root 64 Jun  2 13:34 9 -> pipe:[102655233]


# ls -lha /proc/13559/fd
total 0
dr-x------ 2 root root  0 Jun  2 13:34 .
dr-xr-xr-x 9 root root  0 Jun  2 13:34 ..
lr-x------ 1 root root 64 Jun  2 13:34 0 -> pipe:[102655232]
l-wx------ 1 root root 64 Jun  2 13:34 1 -> pipe:[102655233]
lrwx------ 1 root root 64 Jun  2 13:34 2 -> /dev/pts/8
lr-x------ 1 root root 64 Jun  2 13:34 3 -> /etc/needrestart/needrestart.conf
lr-x------ 1 root root 64 Jun  2 13:34 4 -> 
/usr/share/perl5/NeedRestart/UI/Debconf.pm
lr-x------ 1 root root 64 Jun  2 13:34 5 -> pipe:[102655232]
l-wx------ 1 root root 64 Jun  2 13:34 6 -> pipe:[102655233]
lr-x------ 1 root root 64 Jun  2 13:34 7 -> /proc/29312/cgroup


So the bug might be within Perl?


Regards,
Thomas

-- 

    ::  WWW:                        https://fiasko-nw.net/~thomas/  ::
   :::  Jabber:                   xmpp:tho...@jabber.fiasko-nw.net  :::
    ::  flickr:             https://www.flickr.com/photos/laugufe/  ::

Reply via email to