From 258365e6cd56f9039b4de7723e4950563a163c8b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 30 Oct 2021 08:11:43 +0000 Subject: [PATCH] lei_to_mail: avoid SEGV on worker exit via SIGTERM ->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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm index 90db30e5..3c5e7e59 100644 --- a/lib/PublicInbox/LeiToMail.pm +++ b/lib/PublicInbox/LeiToMail.pm @@ -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]); } -- 2.44.0