diff --git a/src/Build/BackEnd/Client/MSBuildClient.cs b/src/Build/BackEnd/Client/MSBuildClient.cs index be791e7ced8..7812ac55f03 100644 --- a/src/Build/BackEnd/Client/MSBuildClient.cs +++ b/src/Build/BackEnd/Client/MSBuildClient.cs @@ -390,7 +390,7 @@ private void ConfigureAndQueryConsoleProperties() return (acceptAnsiColorCodes: acceptAnsiColorCodes, outputIsScreen: outputIsScreen); } - + private int QueryConsoleBufferWidth() { int consoleBufferWidth = -1; @@ -454,22 +454,23 @@ private bool TrySendPacket(Func packetResolver) private bool TryLaunchServer() { string serverLaunchMutexName = $@"Global\msbuild-server-launch-{_handshake.ComputeHash()}"; - using var serverLaunchMutex = ServerNamedMutex.OpenOrCreateMutex(serverLaunchMutexName, out bool mutexCreatedNew); - if (!mutexCreatedNew) + try { - // Some other client process launching a server and setting a build request for it. Fallback to usual msbuild app build. - CommunicationsUtilities.Trace("Another process launching the msbuild server, falling back to former behavior."); - _exitResult.MSBuildClientExitType = MSBuildClientExitType.ServerBusy; - return false; - } + // For unknown root cause, opening mutex can sometimes throw 'Connection timed out' exception. See: https://github.com/dotnet/msbuild/issues/7993 + using var serverLaunchMutex = ServerNamedMutex.OpenOrCreateMutex(serverLaunchMutexName, out bool mutexCreatedNew); + if (!mutexCreatedNew) + { + // Some other client process launching a server and setting a build request for it. Fallback to usual msbuild app build. + CommunicationsUtilities.Trace("Another process launching the msbuild server, falling back to former behavior."); + _exitResult.MSBuildClientExitType = MSBuildClientExitType.ServerBusy; + return false; + } - string[] msBuildServerOptions = new string[] { - "/nologo", - "/nodemode:8" - }; + string[] msBuildServerOptions = new string[] { + "/nologo", + "/nodemode:8" + }; - try - { NodeLauncher nodeLauncher = new NodeLauncher(); CommunicationsUtilities.Trace("Starting Server..."); Process msbuildProcess = nodeLauncher.Start(_msbuildLocation, string.Join(" ", msBuildServerOptions));