Repository navigation
Closed
Description
Wasn't sure if this was an issue or whether we shouldn't be using msbuild /m to enable concurrent builds.
[11:45:48] [BuildSolution] 17>MSBUILD : warning : WARN [09/02/16 1:45:48:65] Could not determine assembly version: LibGit2Sharp.LockedFileException: The index is locked. This might be due to a concurrent or crashed process [Y:\Work\refs\heads\master\source\Octopus.E2ETests\Octopus.E2ETests.csproj]
[11:45:48] [BuildSolution] MSBUILD : warning : at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) [Y:\Work\refs\heads\master\source\Octopus.E2ETests\Octopus.E2ETests.csproj]
[11:45:48] [BuildSolution] MSBUILD : warning : at LibGit2Sharp.Core.Proxy.git_checkout_tree(RepositoryHandle repo, ObjectId treeId, GitCheckoutOpts& opts) [Y:\Work\refs\heads\master\source\Octopus.E2ETests\Octopus.E2ETests.csproj]
[11:45:48] [BuildSolution] MSBUILD : warning : at LibGit2Sharp.Repository.CheckoutTree(Tree tree, IList`1 paths, IConvertableToGitCheckoutOpts opts) [Y:\Work\refs\heads\master\source\Octopus.E2ETests\Octopus.E2ETests.csproj]
[11:45:48] [BuildSolution] MSBUILD : warning : at LibGit2Sharp.Repository.Checkout(Tree tree, CheckoutOptions checkoutOptions, String refLogHeadSpec) [Y:\Work\refs\heads\master\source\Octopus.E2ETests\Octopus.E2ETests.csproj]
[11:45:48] [BuildSolution] MSBUILD : warning : at LibGit2Sharp.Repository.Checkout(Branch branch, CheckoutOptions options) [Y:\Work\refs\heads\master\source\Octopus.E2ETests\Octopus.E2ETests.csproj]
[11:45:48] [BuildSolution] MSBUILD : warning : at LibGit2Sharp.Repository.Checkout(String committishOrBranchSpec, CheckoutOptions options) [Y:\Work\refs\heads\master\source\Octopus.E2ETests\Octopus.E2ETests.csproj]
[11:45:48] [BuildSolution] MSBUILD : warning : at GitTools.Git.GitRepositoryHelper.EnsureLocalBranchExistsForCurrentBranch(Repository repo, String currentBranch) [Y:\Work\refs\heads\master\source\Octopus.E2ETests\Octopus.E2ETests.csproj]
[11:45:48] [BuildSolution] MSBUILD : warning : at GitTools.Git.GitRepositoryHelper.NormalizeGitDirectory(String gitDirectory, AuthenticationInfo authentication, Boolean noFetch, String currentBranch) [Y:\Work\refs\heads\master\source\Octopus.E2ETests\Octopus.E2ETests.csproj]
[11:45:48] [BuildSolution] MSBUILD : warning : at GitVersion.GitPreparer.Initialise(Boolean normaliseGitDirectory, String currentBranch) [Y:\Work\refs\heads\master\source\Octopus.E2ETests\Octopus.E2ETests.csproj]
[11:45:48] [BuildSolution] MSBUILD : warning : at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig) [Y:\Work\refs\heads\master\source\Octopus.E2ETests\Octopus.E2ETests.csproj]
[11:45:48] [BuildSolution] MSBUILD : warning : at GitVersion.ExecuteCore.TryGetVersion(String directory, VersionVariables& versionVariables, Boolean noFetch, Authentication authentication) [Y:\Work\refs\heads\master\source\Octopus.E2ETests\Octopus.E2ETests.csproj]
This occurs on TeamCity 10.0.0 building ~30 projects. We've only just upgraded to GitVersionTask.3.6.3 from GitVersionTask.3.6.1 which had the gitversion_cache issue.
In the meantime I'll try some more builds and see if it recurs frequently.
Reacted by Teneko, Petar Petrov, Cosmin Popescu and KY Lee
Activity
michaelnoonan commentedon Sep 2, 2016
The very next build through TeamCity failed with the exact same message and stack trace.
I'm going to revert to
msbuildwithout the/mfor now.JakeGinnivan commentedon Sep 3, 2016
Id switch to the exe, run it with /updateAssemblyInfo before building.
We would have to grab a mutex, and block builds until the first task has finished calculating the version then unblock the others and they get the version from the cache.
asbjornu commentedon Sep 5, 2016
Perhaps we could use
.git/index.lockfor this? I believe it would be semantically correct to lock the entire Git repository for all and any change meanwhile we calculate a version. If.git/index.lockexists, we could await version calculation until it's deleted or within a configurable time-out.JakeGinnivan commentedon Sep 5, 2016
Im happy with that
bbowman commentedon Mar 10, 2017
any updates here?
asbjornu commentedon Mar 13, 2017
@bbowman: I'm sorry, but nothing has happened besides agreeing on a solution that is yet to be implemented. We need someone in the team to have time to implement this, or get someone else to submit a PR. I unfortunately have my hands full. Perhaps you or @michaelnoonan can submit a PR?
jnevins-gcm commentedon Aug 16, 2018
any update on this? builds take 4x as long without parallelism :(
asbjornu commentedon Aug 16, 2018
@jnevins-gcm: Sorry, there's nothing new to report on this. If you are able to provide a pull request that fixes this as described in #1031 (comment), it will be merged quickly provided it passes all tests.
jnevins-gcm commentedon Aug 16, 2018
Thanks for the update. Even if I fix, how would I manage to get that into GitVersionTask?
Is there any short term workaround I could do with retries?
asbjornu commentedon Jun 27, 2019
@jnevins-gcm, if you submit a pull request to this repository, it will be merged and a new package of GitVersionTask will show up on NuGet that you can use.
asbjornu commentedon Jun 28, 2019
Now that we've upgraded to LibGit2Sharp version 0.26 in #1713, I hope this problem might be fixed. Please test with the latest v5 beta and reopen if the problem persists.
StevenDevooght commentedon Jul 16, 2019
Hi,
We are having the same issue using the latest beta version (5.0.0-beta5.11).
borrillis commentedon Sep 4, 2019
Also hitting this issue on linux and Windows (but not MacOS) build agents using GitVersion 5.0.1
asbjornu commentedon Sep 4, 2019
@StevenDevooght and @borrillis, can you please tell me more about your build environments that might help us figure out why this is happening?
61 remaining items
teneko commentedon Jun 10, 2020
Thanks for your answering. When I find time, I will try to look around the code in GitVersionCode and seek for a possiblity to wrap each single action that involves GitVersion.yml, caching or LibGit2Sharp by an file lock. Another approach would be to lock on startup and unlock on exit. But that is quick and dirty and reminds me of the time, where you instantiated one SqlConnection during lifetime. 😃
Yes would become a breaking change if someone externals is relying on exact these created caches. But not sure if someone is really working with those temporary cach files that are generated by GitVersion and not by someone elses. I won't change any structure.
I think I have now all infos to proceed when I find time. I hope for weekend or next week.
One question, what lets me open, is a test case: It is quite difficult to create such an environment to test it. My project with its 10+ sub projects that relies on GitVersionTask could serve that kind of test, but it does fail only each second or third time due to LibGit2Sharp.LockedFileException.
What is your idea to make a test case? Maybe a kind of penetration test of a huge project with many sub projects someone can provide us?
Regarding to your distate of Tool and Utility. I can understand you and agree with you, that such a Tool whatever static prupose it does serve, can be lost quickly. But a library is not a library without such functions. Those functions cannot be related to only one purpose easily, So when you have two classes that serves completely its own purposes, but have both one method that share a bit of the same logic like Directory.Exists or File.Exists, then you should outsource them definetely to let them become Directory.Exists and File.Exists. My taste for Tools (or Utilities) are coming for this reason, that I don't want to collide with existing classes from System.*, but want to state its relation to them. So the name LockFileTools comes more or less by habit. When I think more over it: FileLocker does associate a kind of encapsulation between these static functions, so even when I would call it FileLocker: The class itself does not provide a file locker, but each of its static functions. Moreover they do not provide a file locker instead they do lock a file it without an instanstiated context so the name would irritate somehow. But this would change if FileLocker would be instantiable and would require a file path and provides methods like "Lock", then the class itself would be a file locker and therefore named FileLocker. Haha, but I do respect your programming style.☺️
To your last words: I am looking forward that this library will become a strong library. 😊
asbjornu commentedon Jun 10, 2020
Sounds great! 👍
It's a viable choice if other options are too difficult. It's much better than crashing and will still yield better performance with parallelization than a serial build would.
I don't know either.
Good. We can instead harmonize this a bit in v6 and gather everything GitVersion related into a
.git/gitversion/folder.Awesome!
I think we should be able to surface this bug with enough projects in a single solution, so a very simple repository with just a bare minimum solution with perhaps 100 projects all using GitVersionTask should be able to consistently reproduce this bug, I'd assume.
I've set up and invited you to GitVersion.TestCases so we can collaborate on the reproduction there. I'm thinking this one repository can have one branch per test case, starting with this parallelization problem.
My point exactly! I have a general distaste for
staticas well, since unless it's always paired withreadonlyand immutable objects, leads to global mutable state, meaning bugs and bad encapsulation. It's also impossible to mock in tests and generally doesn't play well IOC.So do I! 😃
dmitrynovik commentedon Sep 17, 2020
Guys, the builds failing because of GitVersion creating
*.lockfiles is a really annoying "feature". Any indication on when the PR "A lock file implementation applied to project GitVersionCore for resolving #1031" can be merged ? Looks like there was a work in progress abandoned in July :("
MarkusHorstmann commentedon Feb 5, 2021
Pending PR #2581 has some mitigations (retries) for this issue. Makes a big difference at least for my builds.
github-actions commentedon Feb 7, 2021
🎉 This issue has been resolved in version 5.6.5 🎉
The release is available on:
Your GitReleaseManager bot 📦🚀
workaround for GitVersion file lock
bording commentedon Apr 16, 2021
@arturcic I don't think this issue should be closed. I'm currently using GitVersion.MsBuild 5.6.8 and I'm still seeing
LockedFileExceptionandNameConflictExceptionwhen projects are built in parallel. #1381, which is still open seems to also be relevant here.The problem is that there is a race condition in the NormalizeGitDirectory where two projects building at the same time will both attempt to create the needed branches, and one will fail with
LockedFileExceptionorNameConflictException.Seems like this code needs to be more resilient to failures, because if it just attempted it again, it would see that the required branch does exist.
EDIT: Instead of a retry, seems like a mutex would be a good way to ensure that the normalization code is not being run in parallel since that's the part that needs to be protected.
dominikjeske commentedon Apr 19, 2021
Unfortunately I'm getting this error also using GitVersion.MsBuild 5.6.8 on my TeamCity 2020.1.3.
bording commentedon Apr 21, 2021
I have opened #2669 with my attempt to fix this problem.
rose-a commentedon May 26, 2021
Yup, issue is still there with v5.6.9 (GitLab CI)
bording commentedon May 26, 2021
@rose-a I had a follow-up PR #2676 that has not been released yet. That will be needed to truly fix the issue.
@arturcic Any plans to get that out?
arturcic commentedon May 26, 2021
@bording i will have a look on the PRs in progress and see when we can release