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-ASN: 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 1FA111F670 for ; Fri, 15 Oct 2021 15:52:58 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] lei q: guard query_done against die() Date: Fri, 15 Oct 2021 15:52:57 +0000 Message-Id: <20211015155257.10098-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: v2w->wq_do('done') may die on I/O errors, and likely other places. Just guard the entire block with an eval and ->fail as appropriate. --- lib/PublicInbox/LeiXSearch.pm | 75 ++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm index fd2c8a37..4aa2a81c 100644 --- a/lib/PublicInbox/LeiXSearch.pm +++ b/lib/PublicInbox/LeiXSearch.pm @@ -412,47 +412,48 @@ sub xsearch_done_wait { # dwaitpid callback sub query_done { # EOF callback for main daemon my ($lei) = @_; local $PublicInbox::LEI::current_lei = $lei; - my $l2m = delete $lei->{l2m}; - delete $lei->{lxs}; - ($lei->{opt}->{'mail-sync'} && !$lei->{sto}) and - warn "BUG: {sto} missing with --mail-sync"; - $lei->sto_done_request if $lei->{sto}; - if (my $v2w = delete $lei->{v2w}) { - $v2w->wq_do('done'); - $v2w->wq_close; - } - $lei->{ovv}->ovv_end($lei); - my $start_mua; - if ($l2m) { # close() calls LeiToMail reap_compress - if (my $out = delete $lei->{old_1}) { - if (my $mbout = $lei->{1}) { - close($mbout) or return $lei->fail(<<""); -Error closing $lei->{ovv}->{dst}: $! + eval { + my $l2m = delete $lei->{l2m}; + delete $lei->{lxs}; + ($lei->{opt}->{'mail-sync'} && !$lei->{sto}) and + warn "BUG: {sto} missing with --mail-sync"; + $lei->sto_done_request if $lei->{sto}; + if (my $v2w = delete $lei->{v2w}) { + my $wait = $v2w->wq_do('done'); # may die + $v2w->wq_close; + } + $lei->{ovv}->ovv_end($lei); + if ($l2m) { # close() calls LeiToMail reap_compress + if (my $out = delete $lei->{old_1}) { + if (my $mbout = $lei->{1}) { + close($mbout) or die <<""; +Error closing $lei->{ovv}->{dst}: \$!=$! \$?=$? + } + $lei->{1} = $out; + } + if ($l2m->lock_free) { + $l2m->poke_dst; + $lei->poke_mua; + } else { # mbox users + delete $l2m->{mbl}; # drop dotlock } - $lei->{1} = $out; - } - if ($l2m->lock_free) { - $l2m->poke_dst; - $lei->poke_mua; - } else { # mbox users - delete $l2m->{mbl}; # drop dotlock - $start_mua = 1; } - } - if ($lei->{-progress}) { - my $tot = $lei->{-mset_total} // 0; - my $nr = $lei->{-nr_write} // 0; - if ($l2m) { - my $m = "# $nr written to " . - "$lei->{ovv}->{dst} ($tot matches)"; - $nr ? $lei->qfin($m) : $lei->qerr($m); - } else { - $lei->qerr("# $tot matches"); + if ($lei->{-progress}) { + my $tot = $lei->{-mset_total} // 0; + my $nr = $lei->{-nr_write} // 0; + if ($l2m) { + my $m = "# $nr written to " . + "$lei->{ovv}->{dst} ($tot matches)"; + $nr ? $lei->qfin($m) : $lei->qerr($m); + } else { + $lei->qerr("# $tot matches"); + } } - } - $lei->start_mua if $start_mua; - $lei->dclose; + $lei->start_mua if $l2m && !$l2m->lock_free; + $lei->dclose; + }; + $lei->fail($@) if $@; } sub do_post_augment {