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: signature.asc
Description: OpenPGP digital signature

Reply via email to