Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback when server launch fail due to create mutex error #8000

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/Build/BackEnd/Client/MSBuildClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private void ConfigureAndQueryConsoleProperties()

return (acceptAnsiColorCodes: acceptAnsiColorCodes, outputIsScreen: outputIsScreen);
}

private int QueryConsoleBufferWidth()
{
int consoleBufferWidth = -1;
Expand Down Expand Up @@ -454,22 +454,23 @@ private bool TrySendPacket(Func<INodePacket> 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));
Expand Down