unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] git_async_cat: don't mis-abort replaced process
Date: Mon, 20 Feb 2023 08:19:43 +0000	[thread overview]
Message-ID: <20230220081943.M87032@dcvr> (raw)
In-Reply-To: <20230209012932.M934961@dcvr>

When a git process gets replaced (e.g. due to new
epochs/alternates), we must be careful and not abort the wrong
one.

I suspect this fixes the problem exacerbated by --batch-command.
It was theoretically possible w/o --batch-command, but it seems
to have made it surface more readily.

This should fix "Failed to retrieve generated blob" errors from
PublicInbox/ViewVCS.pm appearing in syslog

Link: https://public-inbox.org/meta/20230209012932.M934961@dcvr/
---
 lib/PublicInbox/GitAsyncCat.pm | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/GitAsyncCat.pm b/lib/PublicInbox/GitAsyncCat.pm
index c428f6ef..671654b5 100644
--- a/lib/PublicInbox/GitAsyncCat.pm
+++ b/lib/PublicInbox/GitAsyncCat.pm
@@ -14,6 +14,12 @@ use PublicInbox::Git ();
 
 our $GCF2C; # singleton PublicInbox::Gcf2Client
 
+# close w/o aborting another git process
+sub vanish {
+	delete $_[0]->{git};
+	$_[0]->close;
+}
+
 sub close {
 	my ($self) = @_;
 	if (my $git = delete $self->{git}) {
@@ -22,19 +28,25 @@ sub close {
 	$self->SUPER::close; # PublicInbox::DS::close
 }
 
-sub aclose { $_[1]->close } # ignore PID ($_[0])
+sub aclose {
+	my (undef, $self, $f) = @_; # ignore PID ($_[0])
+	if (my $g = $self->{git}) {
+		return vanish($self) if ($g->{$f} // 0) != ($self->{sock} // 1);
+	}
+	$self->close;
+}
 
 sub event_step {
 	my ($self) = @_;
 	my $git = $self->{git} or return;
-	return $self->close if ($git->{in} // 0) != ($self->{sock} // 1);
+	return vanish($self) if ($git->{in} // 0) != ($self->{sock} // 1);
 	my $inflight = $git->{inflight};
 	if ($inflight && @$inflight) {
 		$git->cat_async_step($inflight);
 
 		# child death?
 		if (($git->{in} // 0) != ($self->{sock} // 1)) {
-			$self->close;
+			vanish($self);
 		} elsif (@$inflight || exists $git->{rbuf}) {
 			# ok, more to do, requeue for fairness
 			$self->requeue;
@@ -48,7 +60,7 @@ sub watch_cat {
 		my $self = bless { git => $git }, __PACKAGE__;
 		$git->{in}->blocking(0);
 		$self->SUPER::new($git->{in}, EPOLLIN|EPOLLET);
-		awaitpid($git->{pid}, \&aclose, $self);
+		awaitpid($git->{pid}, \&aclose, $self, 'in');
 		\undef; # this is a true ref()
 	};
 }
@@ -81,7 +93,7 @@ sub async_check ($$$$) {
 		my $self = bless { git => $git }, 'PublicInbox::GitAsyncCheck';
 		$git->{in_c}->blocking(0);
 		$self->SUPER::new($git->{in_c}, EPOLLIN|EPOLLET);
-		awaitpid($git->{pid_c}, \&aclose, $self);
+		awaitpid($git->{pid_c}, \&aclose, $self, 'in_c');
 		\undef; # this is a true ref()
 	};
 }
@@ -113,14 +125,14 @@ use PublicInbox::Syscall qw(EPOLLIN EPOLLET);
 sub event_step {
 	my ($self) = @_;
 	my $git = $self->{git} or return;
-	return $self->close if ($git->{in_c} // 0) != ($self->{sock} // 1);
+	return $self->vanish if ($git->{in_c} // 0) != ($self->{sock} // 1);
 	my $inflight = $git->{inflight_c};
 	if ($inflight && @$inflight) {
 		$git->check_async_step($inflight);
 
 		# child death?
 		if (($git->{in_c} // 0) != ($self->{sock} // 1)) {
-			$self->close;
+			$self->vanish;
 		} elsif (@$inflight || exists $git->{rbuf_c}) {
 			# ok, more to do, requeue for fairness
 			$self->requeue;

  reply	other threads:[~2023-02-20  8:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-26  9:32 [PATCH 0/2] use `git cat-file --batch-command' if available Eric Wong
2023-01-26  9:32 ` [PATCH 1/2] git: use --batch-command in git 2.36+ to save processes Eric Wong
2023-01-27  8:14   ` Eric Wong
2023-01-27  8:17     ` Eric Wong
2023-02-09  1:29   ` Eric Wong
2023-02-20  8:19     ` Eric Wong [this message]
2023-01-26  9:32 ` [PATCH 2/2] git: drop needless checks for old git Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230220081943.M87032@dcvr \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).