From: Eric Wong Date: Thu, 6 Apr 2023 12:39:53 +0000 (+0000) Subject: watch: close inotify FD on ->quit X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee9956c21fe969fa9b1fb51d91d5c6956d35e00a;p=thirdparty%2Fpublic-inbox.git watch: close inotify FD on ->quit For simplicity, we quit and recreate an entire watch instance on SIGHUP. However, inotify (and signalfd) FDs are tied to the DS event loop and stay pinned to existence that way. Thus we explicitly close the FD in Watch->quit to prevent leakage on SIGHUP. --- diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm index b87abafed..c7acda14a 100644 --- a/lib/PublicInbox/Watch.pm +++ b/lib/PublicInbox/Watch.pm @@ -256,6 +256,10 @@ sub quit { %{$self->{opendirs}} = (); _done_for_now($self); quit_done($self); + if (defined(my $fd = delete $self->{dir_idle_fd})) { + my $di = $PublicInbox::DS::DescriptorMap{$fd}; + $di->close if $di && $di->can('add_watches'); + } if (my $idle_mic = delete $self->{idle_mic}) { return unless $idle_mic->IsConnected && $idle_mic->Socket; eval { $idle_mic->done }; @@ -280,6 +284,7 @@ sub watch_fs_init ($) { require PublicInbox::DirIdle; # inotify_create + EPOLL_CTL_ADD my $dir_idle = PublicInbox::DirIdle->new($cb); + $self->{dir_idle_fd} = fileno($dir_idle->{sock}) if $dir_idle->{sock}; $dir_idle->add_watches([keys %{$self->{mdmap}}]); }