From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 26F5E1F5B7 for ; Wed, 1 Jul 2020 21:06:20 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/5] watch: retry signals to kill IDLE and polling processes Date: Wed, 1 Jul 2020 21:06:17 +0000 Message-Id: <20200701210619.29601-4-e@yhbt.net> In-Reply-To: <20200701210619.29601-1-e@yhbt.net> References: <20200701210619.29601-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: To ensure reliable signal delivery in Perl, it seems we need to repeatedly signal processes which aren't using signalfd (or EVFILT_SIGNAL) with our event loop. --- lib/PublicInbox/WatchMaildir.pm | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index e3df85159e7..23b2e9f110b 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -202,18 +202,27 @@ sub _try_path { } } +sub quit_done ($) { + my ($self) = @_; + return unless $self->{quit}; + + # don't have reliable wakeups, keep signalling + my $done = 1; + for (qw(idle_pids poll_pids)) { + my $pids = $self->{$_} or next; + for (keys %$pids) { + $done = undef if kill('QUIT', $_); + } + } + $done; +} + sub quit { my ($self) = @_; $self->{quit} = 1; %{$self->{opendirs}} = (); _done_for_now($self); - if (my $imap_pid = $self->{-imap_pid}) { - kill('QUIT', $imap_pid); - } - for (qw(idle_pids poll_pids)) { - my $pids = $self->{$_} or next; - kill('QUIT', $_) for (keys %$pids); - } + quit_done($self); if (my $idle_mic = $self->{idle_mic}) { eval { $idle_mic->done }; if ($@) { @@ -921,8 +930,8 @@ sub watch { [$self, $intvl, $urls]); } watch_fs_init($self) if $self->{mdre}; - PublicInbox::DS->SetPostLoopCallback(sub {}); - PublicInbox::DS->EventLoop until $self->{quit}; + PublicInbox::DS->SetPostLoopCallback(sub { !$self->quit_done }); + PublicInbox::DS->EventLoop; _done_for_now($self); }