From 9f2dfa6dbec4b5e162a9f4812351f567bbc331ee Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 1 May 2023 23:29:35 +0000 Subject: daemon: improve handling of Git->async_abort The $oid arg for Git->cat_async is defined on async_abort using the original request, so use undefined $type to distinguish that case in caller-supplied callbacks. async_abort isn't common, of course, but sometimes git subprocesses can die unexpectedly. --- lib/PublicInbox/GzipFilter.pm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lib/PublicInbox/GzipFilter.pm') diff --git a/lib/PublicInbox/GzipFilter.pm b/lib/PublicInbox/GzipFilter.pm index a37080c8..db8e8397 100644 --- a/lib/PublicInbox/GzipFilter.pm +++ b/lib/PublicInbox/GzipFilter.pm @@ -172,7 +172,7 @@ sub close { (delete($self->{http_out}) // return)->close; } -sub bail { +sub bail { my $self = shift; carp @_; my $env = $self->{env} or return; @@ -188,16 +188,19 @@ sub async_blob_cb { # git->cat_async callback my ($bref, $oid, $type, $size, $self) = @_; my $http = $self->{env}->{'psgix.io'}; # PublicInbox::HTTP $http->{forward} or return; # client aborted - my $smsg = $self->{smsg} or bail($self, 'BUG: no smsg'); - if (!defined($oid)) { + my $smsg = $self->{smsg} or return bail($self, 'BUG: no smsg'); + $type // return + bail($self, "abort: $smsg->{blob} $self->{ibx}->{inboxdir}"); + if ($type ne 'blob') { # it's possible to have TOCTOU if an admin runs # public-inbox-(edit|purge), just move onto the next message - warn "E: $smsg->{blob} missing in $self->{ibx}->{inboxdir}\n"; + warn "E: $smsg->{blob} $type in $self->{ibx}->{inboxdir}\n"; return $http->next_step($self->can('async_next')); } - $smsg->{blob} eq $oid or bail($self, "BUG: $smsg->{blob} != $oid"); + $smsg->{blob} eq $oid or return + bail($self, "BUG: $smsg->{blob} != $oid"); eval { $self->async_eml(PublicInbox::Eml->new($bref)) }; - bail($self, "E: async_eml: $@") if $@; + return bail($self, "E: async_eml: $@") if $@; if ($self->{-low_prio}) { # run via PublicInbox::WWW::event_step push(@{$self->{www}->{-low_prio_q}}, $self) == 1 and PublicInbox::DS::requeue($self->{www}); -- cgit v1.2.3-24-ge0c7