Re: failed to read .git/worktrees/test-worktree-xdrphX/commondir: Success

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 13, 2024 at 3:53 PM Phillip Wood <phillip.wood123@xxxxxxxxx> wrote:
> Unfortunately with the current implementation of "git worktree add" it
> isn't. When git tries to add a new worktree it first checks to see if it
> already exists. As a worktree may be on removable media it cannot simply
> check that the directory does not exist, it also has to check that there
> isn't a locked worktree at that path. To check for a locked worktree it
> has to list all the worktrees in the repository and if another process
> is creating a new worktree at the same time the process trying the list
> the worktrees ends up seeing an corrupt wortree because the other
> process hasn't finished creating all the required files yet. I think
> this is fixable in principle by teaching the code that lists the
> worktrees to ignore ".git/worktrees/*.lock" and creating new worktree
> under ".git/worktrees/$id.lock" and then renaming "$id.lock" to "$id"
> once all the files are written. There are probably some subtleties
> though as we would need to ensure the processes that are spawned to
> setup the worktree use the temporary ".lock" directory.
>
> > Anything I can do to help narrow down the issue?
>
> If you're interested in fixing the problem the relevant code lives in
> worktree.c and builtin/worktree.c. The easiest solution is probably to
> try introduce some locking in your program so you don't run two
> instances of "git worktree add" at the same time.

OK, thanks very much for the info :)

So I think the right approach for me is:

1. Do a silly retry-based workaround in my application to make the
tests stop flaking (doing proper locking is actually nontrivial
because the git commands get run across separate processes).
2. If (big "if" unfortunately) and when I get the time, contribute a
fix to Git as you suggested - thanks for the code pointers.
3. Then I can just have my tests depend on an updated Git. I've never
actually seen the issue in real usage of the application so I think
that's likely to be good enough.

Cheers and thanks again for the help,
Brendan





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux