git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Worktree creation race
@ 2019-01-15 14:03 Marketa Calabkova
  2019-01-28 12:58 ` Marketa Calabkova
  0 siblings, 1 reply; 7+ messages in thread
From: Marketa Calabkova @ 2019-01-15 14:03 UTC (permalink / raw)
  To: git


[-- Attachment #1.1: Type: text/plain, Size: 1322 bytes --]

Hello,

I am writing to report a bug. The original report is from my colleague, I am also providing his suggestions.

There is insufficient locking for worktree addition. Adding worktree may fail.

The problem is that git reads the directory entries in $GIT_DIR/worktrees, 
finds a worktree name that does not exist, tries to create it, and if an 
error is returned adding the worktree fails. When multiple git processes 
do this in parallel only one adds a worktree and the others fail. Git should 
reread the directory and find a new name that does not exist when creating 
the worktree directory fails because another git process already created it.

I suppose adding PID in the tree name would mitigate the issue to the point it will be very unlikely to encounter.

I need more than the tree in the temporary directory so using the temporary directory directly as a tree is out of question.

to test:

cd /dev/shm
mkdir gittest
cd gittest
git init gitrepo
cd gitrepo
git commit --allow-empty -m Empty
for n in $(seq 10000) ; do ( tmp=$(mktemp -d /dev/shm/gittest/test.XXXXXXXXXXX) ; mkdir $tmp/test ; git worktree add --detach $tmp/test ; ) & done

(you should see many messages like: 
fatal: could not create directory of '.git/worktrees/test284': File exists)

Greetings,
Marketa



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-02-01 19:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-15 14:03 Worktree creation race Marketa Calabkova
2019-01-28 12:58 ` Marketa Calabkova
2019-02-01  6:27   ` Eric Sunshine
2019-02-01  7:06     ` Duy Nguyen
2019-02-01 13:16       ` Duy Nguyen
2019-02-01 19:54         ` Eric Sunshine
2019-02-01 18:06     ` Junio C Hamano

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).