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

[PATCH 0/2] worktree add race fix

From
Michal Suchanek <msuchanek@suse.de>
Date
Feb 18, 2019, 17:04 UTC
Message-ID
<cover.1550508544.git.msuchanek@suse.de>
Hello,

I am running a git automation script that crates a tree and commmits it into a git repository repeatedly.

I noticed that the step which creates a tree is most time-consuming part of the script and when a lot of data is to be automatically added to the repository it is benefical to parallelize this part.

To do so I had the script create a dozen worktrees and share the work between them. The problem is automatically creating several worktrees occasioanlly fails.

The most common problem is in the worktree add implementation itself which tries to find an available directory name and then mkdir() it. Of course, doing that several times in parallel causes issues.

When running stress-test to make sure the fix is effective I uncovered additional issues in get_common_dir_noenv. This function is used on each worktree to build a worktree list.

Apparently it can happen that stat() claims there is a commondir file but when trying to open the file it is missing.

Another even rarer issue is that the file might be zero size because another process initializing a worktree opened the file but has not written is content yet.

When any of this happnes git aborts failing to create a worktree because unrelated worktree is not yet fully initialized.

I have tested that these patches fix the issue. However, I expect race against removing/pruning worktrees is still possible.

For previous discussion see
http://public-inbox.org/git/CAPig+cSdpq0Bfq3zSK8kJd6da3dKixK7qYQ24=ZwbuQtsaLNZw@mail.gmail.com/
Michal Suchanek (2):
  worktree: fix worktree add race.
  setup: don't fail if commondir reference is deleted.
 builtin/worktree.c | 12 +++++++-----
 setup.c            | 16 +++++++++++-----
 2 files changed, 18 insertions(+), 10 deletions(-)
-- 
2.20.1
Next: Michal Suchanek
Message 1 of 27 in “worktree add race fix”
  1. 0/2 worktree add race fixMichal Suchanek, Feb 18, 2019
  2. 1/2 worktree: fix worktree add race.Michal Suchanek, Feb 18, 2019
  3. 2/2 setup: don't fail if commondir reference is deleted.Michal Suchanek, Feb 18, 2019
  4. Eric SunshineFeb 18, 2019
  5. Duy NguyenFeb 21, 2019
  6. Michal SuchánekFeb 21, 2019
  7. Phillip WoodFeb 21, 2019
  8. Eric SunshineFeb 21, 2019
  9. Phillip WoodFeb 21, 2019
  10. Michal SuchánekMar 4, 2019
  11. Michal SuchánekFeb 21, 2019
  12. Duy NguyenFeb 22, 2019
  13. Phillip WoodFeb 22, 2019
  14. Duy NguyenFeb 22, 2019
  15. 1/2 worktree: fix worktree add race.Michal Suchanek, Feb 20, 2019
  16. Eric SunshineFeb 20, 2019
  17. Michal SuchánekFeb 20, 2019
  18. Duy NguyenMar 8, 2019
  19. Eric SunshineMar 8, 2019
  20. Junio C HamanoMar 11, 2019
  21. 2/2 setup: don't fail if commondir reference is deleted.Michal Suchanek, Feb 20, 2019
  22. Eric SunshineFeb 20, 2019
  23. Michal SuchánekFeb 20, 2019
  24. Eric SunshineFeb 20, 2019
  25. Eric SunshineFeb 21, 2019
  26. Michal SuchánekFeb 21, 2019
  27. Michal SuchánekFeb 21, 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.