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 53A271F919 for ; Sat, 27 Jun 2020 10:04:03 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 16/34] watch: stop importers before forking Date: Sat, 27 Jun 2020 10:03:42 +0000 Message-Id: <20200627100400.9871-17-e@yhbt.net> In-Reply-To: <20200627100400.9871-1-e@yhbt.net> References: <20200627100400.9871-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This fixes cases where watch is handling both Maildirs and IMAP connections. While we're at it, close open directories in the IMAP children to save FDs. --- lib/PublicInbox/WatchMaildir.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index 494fe7a8f21..24989130979 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -465,11 +465,18 @@ sub watch_atfork_child ($) { my ($self) = @_; delete $self->{idle_pids}; delete $self->{poll_pids}; + delete $self->{opendirs}; PublicInbox::DS->Reset; PublicInbox::Sigfd::sig_setmask($self->{oldset}); %SIG = (%SIG, %{$self->{sig}}); } +sub watch_atfork_parent ($) { + my ($self) = @_; + _done_for_now($self); + $self->{mics} = {}; # going to be forking, so disconnect +} + sub imap_idle_reap { # PublicInbox::DS::dwaitpid callback my ($self, $pid) = @_; my $uri_intvl = delete $self->{idle_pids}->{$pid} or @@ -501,7 +508,7 @@ sub event_step { return if $self->{quit}; my $idle_todo = $self->{idle_todo}; if ($idle_todo && @$idle_todo) { - $self->{mics} = {}; # going to be forking, so disconnect + watch_atfork_parent($self); while (my $uri_intvl = shift(@$idle_todo)) { imap_idle_fork($self, $uri_intvl); } @@ -525,7 +532,7 @@ sub watch_imap_fetch_all ($$) { sub imap_fetch_fork ($$$) { my ($self, $intvl, $uris) = @_; return if $self->{quit}; - $self->{mics} = {}; # going to be forking, so disconnect + watch_atfork_parent($self); defined(my $pid = fork) or die "fork: $!"; if ($pid == 0) { watch_atfork_child($self);