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 +++++++++------
 lib/PublicInbox/IMAP.pm       | 10 ++++++----
 lib/PublicInbox/NNTP.pm       |  6 +++++-
 lib/PublicInbox/POP3.pm       |  5 ++++-
 4 files changed, 24 insertions(+), 12 deletions(-)

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});
diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm
index 37317948..00f99ef7 100644
--- a/lib/PublicInbox/IMAP.pm
+++ b/lib/PublicInbox/IMAP.pm
@@ -592,14 +592,16 @@ sub fetch_blob_cb { # called by git->cat_async via 
ibx_async_cat
        my ($self, undef, $msgs, $range_info, $ops, $partial) = @$fetch_arg;
        my $ibx = $self->{ibx} or return $self->close; # client disconnected
        my $smsg = shift @$msgs or die 'BUG: no smsg';
-       if (!defined($oid)) {
+       if (!defined($type)) {
+               warn "E: git aborted on $oid / $smsg->{blob} $ibx->{inboxdir}";
+               return $self->close;
+       } elsif ($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 $ibx->{inboxdir}\n";
+               warn "E: $smsg->{blob} $type in $ibx->{inboxdir}\n";
                return $self->requeue_once;
-       } else {
-               $smsg->{blob} eq $oid or die "BUG: $smsg->{blob} != $oid";
        }
+       $smsg->{blob} eq $oid or die "BUG: $smsg->{blob} != $oid";
        my $pre;
        ($self->{anon} && !$self->{wbuf} && $msgs->[0]) and
                $pre = ibx_async_prefetch($ibx, $msgs->[0]->{blob},
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 7a91e7eb..316b7775 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -537,7 +537,11 @@ sub blob_cb { # called by git->cat_async via ibx_async_cat
        my ($bref, $oid, $type, $size, $smsg) = @_;
        my $self = $smsg->{nntp};
        my $code = $smsg->{nntp_code};
-       if (!defined($oid)) {
+       if (!defined($type)) {
+               warn "E: git aborted on $oid / $smsg->{blob} ".
+                       $self->{-ibx}->{inboxdir};
+               return $self->close;
+       } elsif ($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 $smsg->{-ibx}->{inboxdir}\n";
diff --git a/lib/PublicInbox/POP3.pm b/lib/PublicInbox/POP3.pm
index 5f992e14..d32793e4 100644
--- a/lib/PublicInbox/POP3.pm
+++ b/lib/PublicInbox/POP3.pm
@@ -216,7 +216,10 @@ sub retr_cb { # called by git->cat_async via ibx_async_cat
        my ($self, $off, $top_nr) = @$args;
        my $hex = $self->{cache}->[$off * 3 + 2] //
                die "BUG: no hex (oid=$oid)";
-       if (!defined($oid)) {
+       if (!defined($type)) {
+               warn "E: git aborted on $oid / $hex $self->{ibx}->{inboxdir}";
+               return $self->close;
+       } elsif ($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: $hex missing in $self->{ibx}->{inboxdir}\n";

Reply via email to