From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 0C9731F452 for ; Tue, 11 Apr 2023 11:23:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1681212231; bh=hErhszdVJk8ZA6f5Q42pRM0SQpaJ0ar98uJi5MLFoaM=; h=From:To:Subject:Date:From; b=5pW65fyU8gmaWMZnTTiZQoXq6vIgU5qyGwptVoRIWouZXEW+TX53hrO00zKC/UrWD uhItLjRsY//74l7d7WNazNOxCq9mcM5bvGAQ+kNdHgUGXhJINzBDGd2SEjHOSXihU7 qZNw8s+hbWM7QN6zgVRlwhE389+sdCbyX/1wzRBc= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] git: fix cat_async_retry Date: Tue, 11 Apr 2023 11:23:50 +0000 Message-Id: <20230411112350.297099-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Retrying requests on alternates changing was causing inflight requests to get lost due to {inflight} getting clobbered by batch_prepare. Unfortunately, reproducing this is difficult without mocking ->alternates_changed. SearchIdx now avoids calling ->batch_prepare directly and relies on more common API functions. Fixes: 65db62eb006f ("git: use --batch-command in git 2.36+ to save processes") --- lib/PublicInbox/Git.pm | 11 +++++------ lib/PublicInbox/SearchIdx.pm | 6 +++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index e35d5277..f153237b 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -229,8 +229,7 @@ sub cat_async_retry ($$) { delete $self->{inflight}; cleanup($self); - $self->{inflight} = $inflight; - batch_prepare($self); + batch_prepare($self, $inflight); my $buf = ''; for (my $i = 0; $i < @$inflight; $i += 3) { $buf .= "$inflight->[$i]\n"; @@ -312,8 +311,8 @@ sub cat_async_wait ($) { } } -sub batch_prepare ($) { - my ($self) = @_; +sub batch_prepare ($$) { + my ($self, $inflight) = @_; check_git_exe(); if ($GIT_VER ge BATCH_CMD_VER) { _bidi_pipe($self, qw(batch-command in out pid err_c)); @@ -321,7 +320,7 @@ sub batch_prepare ($) { } else { _bidi_pipe($self, qw(batch in out pid)); } - $self->{inflight} = []; + $self->{inflight} = $inflight; } sub _cat_file_cb { @@ -581,7 +580,7 @@ sub cat_async_begin { my ($self) = @_; cleanup($self) if $self->alternates_changed; die 'BUG: already in async' if $self->{inflight}; - batch_prepare($self); + batch_prepare($self, []); } sub cat_async ($$$;$) { diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 496cea05..3415cce4 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -1074,7 +1074,11 @@ sub _index_sync { my $ibx = $self->{ibx}; local $self->{current_info} = "$ibx->{inboxdir}"; $self->{batch_bytes} = $opt->{batch_size} // $BATCH_BYTES; - $ibx->git->batch_prepare; + + if ($X->{CLOEXEC_UNSET}) { + $ibx->git->cat_file($tip); + $ibx->git->check($tip); + } my $pr = $opt->{-progress}; my $sync = { reindex => $opt->{reindex}, -opt => $opt, ibx => $ibx }; my $quit = quit_cb($sync);