]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
daemon: improve handling of Git->async_abort
authorEric Wong <e@80x24.org>
Mon, 1 May 2023 23:29:35 +0000 (23:29 +0000)
committerEric Wong <e@80x24.org>
Tue, 2 May 2023 13:06:36 +0000 (13:06 +0000)
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
lib/PublicInbox/IMAP.pm
lib/PublicInbox/NNTP.pm
lib/PublicInbox/POP3.pm

index a37080c8f859a3c5c1eba9b9a5f87df3b0fc56bc..db8e8397bcf83c979f4bc1f4d51d9a41dec11de3 100644 (file)
@@ -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});
index 37317948490234f0c9ce2dc75f5bacc4541501ea..00f99ef75926a707148bc5c8548458c011c11cc9 100644 (file)
@@ -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},
index 7a91e7ebfe49d158080d3a3bbabc0c630b5997da..316b7775865ba1f856c86f6a05a0296e9305a38b 100644 (file)
@@ -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";
index 5f992e14f323fc531e545319469647fa47eb06fd..d32793e492da80a31680846fc25d23c07a8d7d71 100644 (file)
@@ -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";