diff options
author | Eric Wong <e@80x24.org> | 2023-10-08 18:54:03 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-10-08 18:54:42 +0000 |
commit | c8b757d945040426f8c4cd909c2f05e34be6ccb1 (patch) | |
tree | 760cd0f1e7e67961cc65cec13a181eda8c345ff5 /lib | |
parent | e522fd43913f26db5b99f2417a0d863439634ff5 (diff) | |
download | public-inbox-c8b757d945040426f8c4cd909c2f05e34be6ccb1.tar.gz |
It's safer against deadlocks and we still get proper error reporting by passing stderr across in addition to the lei socket.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/PublicInbox/LEI.pm | 9 | ||||
-rw-r--r-- | lib/PublicInbox/LeiInput.pm | 2 | ||||
-rw-r--r-- | lib/PublicInbox/LeiStore.pm | 17 | ||||
-rw-r--r-- | lib/PublicInbox/LeiXSearch.pm | 6 |
4 files changed, 16 insertions, 18 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 1ba2c2a1..e2b3c0d9 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -1537,12 +1537,11 @@ sub lms { sub sto_done_request { my ($lei, $wq) = @_; - return unless $lei->{sto}; + return unless $lei->{sto} && $lei->{sto}->{-wq_s1}; local $current_lei = $lei; - my $sock = $wq ? $wq->{lei_sock} : undef; - $sock //= $lei->{sock}; - my @io; - push(@io, $sock) if $sock; # async wait iff possible + my $s = ($wq ? $wq->{lei_sock} : undef) // $lei->{sock}; + my $errfh = $lei->{2} // *STDERR{GLOB}; + my @io = $s ? ($errfh, $s) : ($errfh); eval { $lei->{sto}->wq_io_do('done', \@io) }; warn($@) if $@; } diff --git a/lib/PublicInbox/LeiInput.pm b/lib/PublicInbox/LeiInput.pm index 91383265..93f8b6b8 100644 --- a/lib/PublicInbox/LeiInput.pm +++ b/lib/PublicInbox/LeiInput.pm @@ -467,7 +467,7 @@ sub process_inputs { } # always commit first, even on error partial work is acceptable for # lei <import|tag|convert> - my $wait = $self->{lei}->{sto}->wq_do('done') if $self->{lei}->{sto}; + $self->{lei}->sto_done_request; $self->{lei}->fail($err) if $err; } diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm index 0cb78f79..e19ec88e 100644 --- a/lib/PublicInbox/LeiStore.pm +++ b/lib/PublicInbox/LeiStore.pm @@ -582,19 +582,20 @@ sub xchg_stderr { } sub done { - my ($self, $sock_ref) = @_; - my $err = ''; + my ($self) = @_; + my ($errfh, $lei_sock) = @$self{0, 1}; # via sto_done_request + my @err; if (my $im = delete($self->{im})) { eval { $im->done }; - if ($@) { - $err .= "import done: $@\n"; - warn $err; - } + push(@err, "E: import done: $@\n") if $@; } delete $self->{lms}; - $self->{priv_eidx}->done; # V2Writable::done + eval { $self->{priv_eidx}->done }; # V2Writable::done + push(@err, "E: priv_eidx done: $@\n") if $@; + print { $errfh // *STDERR{GLOB} } @err; + send($lei_sock, 'child_error 256', 0) if @err && $lei_sock; xchg_stderr($self); - die $err if $err; + die @err if @err; } sub ipc_atfork_child { diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm index 1caa9d06..4077191f 100644 --- a/lib/PublicInbox/LeiXSearch.pm +++ b/lib/PublicInbox/LeiXSearch.pm @@ -358,9 +358,7 @@ sub query_remote_mboxrd { $fh = IO::Uncompress::Gunzip->new($fh, MultiStream => 1); PublicInbox::MboxReader->mboxrd($fh, \&each_remote_eml, $self, $lei, $each_smsg); - if (delete($self->{-sto_imported})) { - my $wait = $self->{import_sto}->wq_do('done'); - } + $lei->sto_done_request if delete($self->{-sto_imported}); $reap_curl->join; my $nr = delete $lei->{-nr_remote_eml} // 0; if ($? == 0) { @@ -402,7 +400,7 @@ sub query_done { # EOF callback for main daemon delete $lei->{lxs}; ($lei->{opt}->{'mail-sync'} && !$lei->{sto}) and warn "BUG: {sto} missing with --mail-sync"; - $lei->sto_done_request if $lei->{sto}; + $lei->sto_done_request; if (my $v2w = delete $lei->{v2w}) { my $wait = $v2w->wq_do('done'); # may die $v2w->wq_close; |