]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: keep $lei around until workers are reaped
authorEric Wong <e@80x24.org>
Mon, 1 Feb 2021 08:28:20 +0000 (22:28 -1000)
committerEric Wong <e@80x24.org>
Mon, 1 Feb 2021 11:38:14 +0000 (11:38 +0000)
This prevents SharedKV->DESTROY in lei-daemon from triggering
before DB handles are closed in lei2mail processes.  The
{each_smsg_not_done} pipe was not sufficient in this case:
that gets closed at the end of the last git_to_mail callback
invocation.

lib/PublicInbox/IPC.pm
lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiXSearch.pm

index 37f029446ad75d13ee58257e84f76f9968874c1c..689f32d0dc690a74058414d419f56b23d86c9f29 100644 (file)
@@ -137,7 +137,7 @@ sub ipc_worker_spawn {
 }
 
 sub ipc_worker_reap { # dwaitpid callback
-       my ($self, $pid) = @_;
+       my ($args, $pid) = @_;
        return if !$?;
        # TERM(15) is our default exit signal, PIPE(13) is likely w/ pager
        my $s = $? & 127;
@@ -145,9 +145,9 @@ sub ipc_worker_reap { # dwaitpid callback
 }
 
 sub wq_wait_old {
-       my ($self) = @_;
+       my ($self, $args) = @_;
        my $pids = delete $self->{"-wq_old_pids.$$"} or return;
-       dwaitpid($_, \&ipc_worker_reap, $self) for @$pids;
+       dwaitpid($_, \&ipc_worker_reap, [$self, $args]) for @$pids;
 }
 
 # for base class, override in sub classes
@@ -164,7 +164,7 @@ sub ipc_atfork_child {
 
 # idempotent, can be called regardless of whether worker is active or not
 sub ipc_worker_stop {
-       my ($self) = @_;
+       my ($self, $args) = @_;
        my ($pid, $ppid) = delete(@$self{qw(-ipc_pid -ipc_ppid)});
        my ($w_req, $r_res) = delete(@$self{qw(-ipc_req -ipc_res)});
        if (!$w_req && !$r_res) {
@@ -175,7 +175,7 @@ sub ipc_worker_stop {
        $w_req = $r_res = undef;
 
        return if $$ != $ppid;
-       dwaitpid($pid, \&ipc_worker_reap, $self);
+       dwaitpid($pid, \&ipc_worker_reap, [$self, $args]);
 }
 
 # use this if we have multiple readers reading curl or "pigz -dc"
index c0b904513a0e7bc8a814bbbbeab3af79aeed58f4..4f7ed17109ae3f72b21b49f5a97ccb1c730c2ddf 100644 (file)
@@ -860,7 +860,7 @@ sub dclose {
                if ($wq->wq_kill) {
                        $wq->wq_close
                } elsif ($wq->wq_kill_old) {
-                       $wq->wq_wait_old;
+                       $wq->wq_wait_old($self);
                }
        }
        close(delete $self->{1}) if $self->{1}; # may reap_compress
index de82a7daee1d4b5a20227e3f4819bc69d330cacb..b4a9b89dc169f9f9f2a0f132cfb8b32c91c8ef52 100644 (file)
@@ -283,7 +283,7 @@ sub query_done { # EOF callback
        my $has_l2m = exists $lei->{l2m};
        for my $f (qw(lxs l2m)) {
                my $wq = delete $lei->{$f} or next;
-               $wq->wq_wait_old;
+               $wq->wq_wait_old($lei);
        }
        $lei->{ovv}->ovv_end($lei);
        if ($has_l2m) { # close() calls LeiToMail reap_compress
@@ -359,7 +359,7 @@ sub sigpipe_handler { # handles SIGPIPE from l2m/lxs workers
        my ($lei) = @_;
        my $lxs = delete $lei->{lxs};
        if ($lxs && $lxs->wq_kill_old) { # is this the daemon?
-               $lxs->wq_wait_old;
+               $lxs->wq_wait_old($lei);
        }
        close(delete $lei->{1}) if $lei->{1};
        $lei->x_it(13);