git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Worktree creation race

From
MCMarketa Calabkova <mcalabkova@suse.cz>
Date
Jan 28, 2019, 12:58 UTC
Message-ID
<2ee89ff3-e672-e940-f601-aa1d2647756a@suse.cz>
In-Reply-To
<89985b60-4c28-ebf0-64b1-8da75263d745@suse.cz>
Hi,

you have probably overseen my email :) . Please, I would like to get it fixed.

Does anyone has a suggestion what to do with this bug? It looks like a one-line fix probably in builtin/worktree.c, but I have no idea how to do it. Sorry.

Thank you, Marketa

On 15/01/2019 15:03, Marketa Calabkova wrote:
Show 34 quoted lines
> 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
>
>
Previous: Marketa CalabkovaNext: Eric Sunshine
Message 2 of 7 in “Worktree creation race”
  1. Marketa CalabkovaJan 15, 2019
  2. Marketa CalabkovaJan 28, 2019
  3. Eric SunshineFeb 1, 2019
  4. Duy NguyenFeb 1, 2019
  5. Duy NguyenFeb 1, 2019
  6. Eric SunshineFeb 1, 2019
  7. Junio C HamanoFeb 1, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.