]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_to_mail: avoid SEGV on worker exit via SIGTERM
authorEric Wong <e@80x24.org>
Sat, 30 Oct 2021 08:11:43 +0000 (08:11 +0000)
committerEric Wong <e@80x24.org>
Sat, 30 Oct 2021 18:34:34 +0000 (18:34 +0000)
->DESTROY ordering via "exit()" calls is tricky, and dedupe
checks were causing problems.

AFAIK, this only affects users who manually enable WAL on
lei/store/ei*/over.sqlite3.  Fortunately, there is no data
corruption as a result even though "read-only" WAL requires
write permissions.

lib/PublicInbox/LeiToMail.pm

index 90db30e53089942be3c512033e23f17147089e39..3c5e7e59e8eedf3b2108a70a076e0ea83d18509c 100644 (file)
@@ -756,6 +756,12 @@ sub ipc_atfork_child {
        $lei->_lei_atfork_child;
        $lei->{auth}->do_auth_atfork($self) if $lei->{auth};
        $SIG{__WARN__} = PublicInbox::Eml::warn_ignore_cb();
+       $self->{git} = $self->{lei}->{ale}->git;
+       $SIG{TERM} = sub { # avoid ->DESTROY ordering problems
+               my $git = delete $self->{git};
+               $git->async_wait_all if $git;
+               exit(15 + 128);
+       };
        $self->SUPER::ipc_atfork_child;
 }
 
@@ -776,7 +782,7 @@ sub write_mail { # via ->wq_io_do
        my ($self, $smsg, $eml) = @_;
        return $self->{wcb}->(undef, $smsg, $eml) if $eml;
        $smsg->{-lms_rw} = $self->{-lms_rw};
-       $self->{lei}->{ale}->git->cat_async($smsg->{blob}, \&git_to_mail,
+       $self->{git}->cat_async($smsg->{blob}, \&git_to_mail,
                                [$self->{wcb}, $smsg]);
 }