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 B32721FFB0 for ; Mon, 1 Feb 2021 08:28:34 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 08/21] lei: keep $lei around until workers are reaped Date: Sun, 31 Jan 2021 22:28:20 -1000 Message-Id: <20210201082833.3293-9-e@80x24.org> In-Reply-To: <20210201082833.3293-1-e@80x24.org> References: <20210201082833.3293-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 10 +++++----- lib/PublicInbox/LEI.pm | 2 +- lib/PublicInbox/LeiXSearch.pm | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/IPC.pm b/lib/PublicInbox/IPC.pm index 37f02944..689f32d0 100644 --- a/lib/PublicInbox/IPC.pm +++ b/lib/PublicInbox/IPC.pm @@ -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" diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index c0b90451..4f7ed171 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -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 diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm index de82a7da..b4a9b89d 100644 --- a/lib/PublicInbox/LeiXSearch.pm +++ b/lib/PublicInbox/LeiXSearch.pm @@ -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);