about summary refs log tree commit homepage
path: root/script
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-09-19 09:37:11 +0000
committerEric Wong <e@80x24.org>2020-09-19 21:39:45 +0000
commitdc03cabb5d167618797e9e8a6ec615bda7b0638b (patch)
tree92b55c227d80cca785ac0c2edb0acb0c5c956549 /script
parent7c0c47e26af17918031d449d24abe40ad452f51a (diff)
downloadpublic-inbox-dc03cabb5d167618797e9e8a6ec615bda7b0638b.tar.gz
Since we only get OIDs from trusted local data sources
(over.sqlite3), we can safely retry within the -gcf2 process
without worry about clients spamming us with requests for
invalid OIDs and triggering reopens.
Diffstat (limited to 'script')
-rwxr-xr-xscript/public-inbox-gcf225
1 files changed, 23 insertions, 2 deletions
diff --git a/script/public-inbox-gcf2 b/script/public-inbox-gcf2
index 51811698..d2d2ac8b 100755
--- a/script/public-inbox-gcf2
+++ b/script/public-inbox-gcf2
@@ -3,12 +3,33 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 eval { require PublicInbox::Gcf2 };
 die "libgit2 development package or Inline::C missing for $0: $@\n" if $@;
+my @dirs; # may get big (30K-100K)
 my $gcf2 = PublicInbox::Gcf2::new();
+use IO::Handle; # autoflush
+STDERR->autoflush(1);
+STDOUT->autoflush(1);
+
 while (<STDIN>) {
         chomp;
         if (m!\A/!) { # +/path/to/git-dir
+                push @dirs, $_;
                 $gcf2->add_alternate("$_/objects");
-        } else {
-                $gcf2->cat_oid(1, $_);
+        } elsif (!$gcf2->cat_oid(1, $_)) {
+                # retry once if missing.  We only get unabbreviated OIDs
+                # from SQLite or Xapian DBs, here, so malicious clients
+                # can't trigger excessive retries:
+                my $oid = $_;
+                warn "I: $$ $oid missing, retrying...\n";
+
+                # clients may need to wait a bit for this:
+                $gcf2 = PublicInbox::Gcf2::new();
+                $gcf2->add_alternate("$_/objects") for @dirs;
+
+                if ($gcf2->cat_oid(1, $oid)) {
+                        warn "I: $$ $oid found after retry\n";
+                } else {
+                        warn "W: $$ $oid missing after retry\n";
+                        print "$oid missing\n"; # mimic git-cat-file
+                }
         }
 }