user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] lei q: guard query_done against die()
Date: Fri, 15 Oct 2021 15:52:57 +0000	[thread overview]
Message-ID: <20211015155257.10098-1-e@80x24.org> (raw)

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 {

                 reply	other threads:[~2021-10-15 15:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211015155257.10098-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).