From: Eric Wong <e@80x24.org>
Date: Thu, 26 Dec 2019 10:47:12 +0000 (+0000)
Subject: wwwlisting: do not rely on $? after ProcessPipe::CLOSE
X-Git-Tag: v1.3.0~184
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=3647997eaf49410bbf3e33bfb3874c611ab0c38b;p=public-inbox.git

wwwlisting: do not rely on $? after ProcessPipe::CLOSE

ProcessPipe::CLOSE won't reliably set $? inside the event loop
if waitpid(..., WNOHANG) isn't successful.  So use a blocking
waitpid() call, here, and hope "git show-ref" exits promptly
since we've already drained its stdout.
---

diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm
index bcb968af..e19ae8a1 100644
--- a/lib/PublicInbox/WwwListing.pm
+++ b/lib/PublicInbox/WwwListing.pm
@@ -127,7 +127,9 @@ sub _json () {
 
 sub fingerprint ($) {
 	my ($git) = @_;
-	my $fh = $git->popen('show-ref') or
+	# TODO: convert to qspawn for fairness when there's
+	# thousands of repos
+	my ($fh, $pid) = $git->popen('show-ref') or
 		die "popen($git->{git_dir} show-ref) failed: $!";
 
 	my $dig = Digest::SHA->new(1);
@@ -135,6 +137,7 @@ sub fingerprint ($) {
 		$dig->add($buf);
 	}
 	close $fh;
+	waitpid($pid, 0);
 	return if $?; # empty, uninitialized git repo
 	$dig->hexdigest;
 }