From: Junio C Hamano <gitster@pobox.com>
To: Stefan Haller <lists@haller-berlin.de>
Cc: git@vger.kernel.org
Subject: Re: Concurrent fetch commands
Date: Sun, 31 Dec 2023 09:27:19 -0800 [thread overview]
Message-ID: <xmqqy1daffk8.fsf@gitster.g> (raw)
In-Reply-To: <c11ca0b3-aaf4-4a8d-80a1-3832954aa7aa@haller-berlin.de> (Stefan Haller's message of "Sun, 31 Dec 2023 14:30:05 +0100")
Stefan Haller <lists@haller-berlin.de> writes:
> I can reliably reproduce this by doing
>
> $ git fetch&; sleep 0.1; git pull
> [1] 42160
> [1] + done git fetch
> fatal: Cannot rebase onto multiple branches.
I see a bug here.
How this _ought_ to work is
- The first "git fetch" wants to report what it fetched by writing
into the $GIT_DIR/FETCH_HEAD file ("git merge FETCH_HEAD" after
the fetch finishes can consume its contents).
- The second "git pull" runs "git fetch" under the hood. Because
it also wants to write to $GIT_DIR/FETCH_HEAD, and because there
is already somebody writing to the file, it should notice and
barf, saying "fatal: a 'git fetch' is already working" or
something.
But because there is no "Do not overwrite FETCH_HEAD somebody else
is using" protection, "git merge" or "git rebase" that is run as the
second half of the "git pull" ends up working on the contents of
FETCH_HEAD that is undefined, and GIGO result follows.
The "bug" that the second "git fetch" does not notice an already
running one (who is in possession of FETCH_HEAD) and refrain from
starting is not easy to design a fix for---we cannot just abort by
opening it with O_CREAT|O_EXCL because it is a normal thing for
$GIT_DIR/FETCH_HEAD to exist after the "last" fetch. We truncate
its contents before starting to avoid getting affected by contents
leftover by the last fetch, but when there is a "git fetch" that is
actively running, and it finishes _after_ the second one starts and
truncates the file, the second one will end up seeing the contents
the first one left. We have the "--no-write-fetch-head" option for
users to explicitly tell which invocation of "git fetch" should not
write FETCH_HEAD.
Running "background/priming" fetches (the one before "sleep 0.1" you
have) is not a crime by itself, but it is a crime to run them
without the "--no-fetch-head" option. Since you have *NO* intention
of using its contents to feed a "git merge" (or equivalent)
yourself, you are breaking your "git pull" step in your example
reproduction yourself.
next prev parent reply other threads:[~2023-12-31 17:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-31 13:30 Concurrent fetch commands Stefan Haller
2023-12-31 13:48 ` Dragan Simic
2023-12-31 13:50 ` Konstantin Tokarev
2023-12-31 14:01 ` Dragan Simic
2024-01-01 11:23 ` Stefan Haller
2024-01-01 15:47 ` Federico Kircheis
2023-12-31 17:27 ` Junio C Hamano [this message]
2023-12-31 17:41 ` Dragan Simic
2024-01-01 11:30 ` Stefan Haller
2024-01-01 11:42 ` Stefan Haller
2024-01-03 7:33 ` Patrick Steinhardt
2024-01-03 8:11 ` Patrick Steinhardt
[not found] ` <ZZU1TCyQdLqoLxPw@ugly>
2024-01-03 10:40 ` Patrick Steinhardt
2024-01-03 16:40 ` Taylor Blau
2024-01-03 22:10 ` Junio C Hamano
2024-01-04 12:01 ` Stefan Haller
2024-01-04 20:54 ` Mike Hommey
2024-01-04 22:14 ` Junio C Hamano
2024-01-04 22:25 ` Mike Hommey
2024-01-04 17:34 ` Taylor Blau
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: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqy1daffk8.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=lists@haller-berlin.de \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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).