From 0cc930929aa04d56b5f7b7c358024dd31a96aa60 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Wed, 21 Apr 2021 14:48:26 -0400 Subject: [PATCH 1/2] Add global mutex to prevent concurrent use --- src/GitVersion.App/GitVersionExecutor.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/GitVersion.App/GitVersionExecutor.cs b/src/GitVersion.App/GitVersionExecutor.cs index 1a4fa2907d..0631ff2deb 100644 --- a/src/GitVersion.App/GitVersionExecutor.cs +++ b/src/GitVersion.App/GitVersionExecutor.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Reflection; +using System.Threading; using GitVersion.Configuration; using GitVersion.Extensions; using GitVersion.Logging; @@ -56,8 +57,16 @@ public int Execute(GitVersionOptions gitVersionOptions) private int RunGitVersionTool(GitVersionOptions gitVersionOptions) { + var mutexName = gitVersionOptions.WorkingDirectory.Replace("\\", ""); + using var mutex = new Mutex(true, $@"Global\{mutexName}", out var acquired); + try { + if (!acquired) + { + mutex.WaitOne(); + } + var variables = gitVersionCalculateTool.CalculateVersionVariables(); var configuration = configProvider.Provide(overrideConfig: gitVersionOptions.ConfigInfo.OverrideConfig); @@ -92,6 +101,10 @@ private int RunGitVersionTool(GitVersionOptions gitVersionOptions) } return 1; } + finally + { + mutex.ReleaseMutex(); + } return 0; } From df0d8dea2b08fa5b81b91279d687ac0ada30033e Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Wed, 28 Apr 2021 15:06:39 -0400 Subject: [PATCH 2/2] Use Path.DirectorySeparatorChar to create mutex name --- src/GitVersion.App/GitVersionExecutor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitVersion.App/GitVersionExecutor.cs b/src/GitVersion.App/GitVersionExecutor.cs index 0631ff2deb..0f10152c13 100644 --- a/src/GitVersion.App/GitVersionExecutor.cs +++ b/src/GitVersion.App/GitVersionExecutor.cs @@ -57,7 +57,7 @@ public int Execute(GitVersionOptions gitVersionOptions) private int RunGitVersionTool(GitVersionOptions gitVersionOptions) { - var mutexName = gitVersionOptions.WorkingDirectory.Replace("\\", ""); + var mutexName = gitVersionOptions.WorkingDirectory.Replace(Path.DirectorySeparatorChar.ToString(), ""); using var mutex = new Mutex(true, $@"Global\{mutexName}", out var acquired); try