question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

windows chunking git lock race condition when run through husky

See original GitHub issue

Description

When the chunked files are split up into enough groups the chance of a race condition on calling git add increases. If chunk a calls git add while chunk b is adding there will be a git.lock file which will make the process fail.

tested on latest version of husky and lint-staged but still occurs. Originally experienced with lint-staged: 10.0.9 husky: 3.0.9

Tested with lint-staged: 10.1.2 husky: 4.2.3

Issue appears to be in gitWorkflow.js

await Promise.all(
      // stagedFileChunks includes staged files that lint-staged originally detected.
      // Add only these files so any 3rd-party edits to other files won't be included in the commit.
      this.stagedFileChunks.map(stagedFiles => this.execGit(['add', '--', ...stagedFiles]))
    )

There is no way to make sure that the git add commands are concurrent for chunks to prevent having a git lock scenario.

Steps to reproduce

Merged 1k+ files where there are lint changes to be applied call through husky on windows

configuration: “husky”: { “hooks”: { “pre-commit”: “lint-staged” } }, “lint-staged”: { “.{ts,tsx}": “eslint --quiet --fix --cache”, ".scss”: “stylelint --syntax=scss” },

Debug Logs

expand to view
Applying modifications... [failed]
→ fatal: Unable to create '{repo}/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
Restoring unstaged changes to partially staged files... [started]
Restoring unstaged changes to partially staged files... [completed]
Cleaning up... [started]
Cleaning up... [completed]

Environment

OS: Windows 10 Node.js v10.16.1 lint-staged: latest 10.x

Previously there was a bug pre-10 where windows would fail due to command-line args length Upgraded to 10 to fix this but keep hitting async issues with git when merging multiple chunks. The issue at the time of raising was a merge of 47 chunks.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:20

github_iconTop GitHub Comments

1reaction
iirojcommented, Apr 9, 2020

I actually managed to implement this feature in the same PR!

Since we already go through all (chunked) tasks in runAll, we can add all matched files to a Set, which will by definition contain unique items.

Then I just pass this set instead of the full chunkedFilepaths to GitWorkflow, chunk it, and then run git add “serially” for all the chunks.

1reaction
iirojcommented, Apr 9, 2020

Thanks for the suggestion. This particular place is the only one where the entire stagedFileChunks is used after generating the tasks, which need all files for matching.

It would certainly be possible to create a (smaller) list of matched files, and then chunk that for the git add part. I haven’t done it because it has not been a priority, and to be honest I didn’t think about it.

I appreciate your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How does Git or libgit2 deal with race conditions?
When Git needs to update a file with a fixed name, like the index or a reference, it creates a file with the...
Read more >
Lint-staged - Run Linters on Git Staged Files - Morioh
lint-staged - Run Linters on git Staged Files - Interview with Andrey ... The problem can be solved by using packages like husky...
Read more >
Skloot, Rebecca - The Immortal Life Of Henrietta Lacks
got one, they'd scream and run through fields, snatching armfuls of ripe fruit and walnuts that the winds blew from the trees. Like...
Read more >
tc 3-22.69 advanced situational awareness
Adaptability is the ability to adjust to new or changing conditions. It is important to build adaptability through contingency planning and ...
Read more >
Help - My Dog Is Scared of Going Outside! - K9 of Mine
It can also elevate your dog's stress levels, since dogs release a lot of mental stress by sniffing and exploring their environment via...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found