Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,24 @@ public static bool IsRunningOnMono
}
}
}
/// <summary>
/// Are we running on .NET 5 or later using the Mono runtime?
/// Will also return true when running on Mono itself; if necessary
/// we can use IsRunningOnMono to distinguish.
/// </summary>
public static bool IsUsingMonoRuntime
{
get
{
try
{
return !(Type.GetType("Mono.RuntimeStructs", throwOnError: false) is null);
}
catch
{
return false;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void ConnectToServerFails()
// to connect. When it fails it should fall back to in-proc
// compilation.
bool holdsMutex;
using (var serverMutex = new Mutex(initiallyOwned: true,
using (var serverMutex = BuildServerConnection.OpenOrCreateMutex(
name: BuildServerConnection.GetServerMutexName(_pipeName),
createdNew: out holdsMutex))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void MutexStopsServerStarting()
var mutexName = BuildServerConnection.GetServerMutexName(pipeName);

bool holdsMutex;
using (var mutex = new Mutex(initiallyOwned: true,
using (var mutex = BuildServerConnection.OpenOrCreateMutex(
name: mutexName,
createdNew: out holdsMutex))
{
Expand All @@ -119,7 +119,7 @@ public void MutexStopsServerStarting()
}
finally
{
mutex.ReleaseMutex();
mutex.Dispose();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public async Task ServerFailsWithLongTempPathUnix()
var newTempDir = _tempDirectory.CreateDirectory(new string('a', 100 - _tempDirectory.Path.Length));
await ApplyEnvironmentVariables(
new[] { new KeyValuePair<string, string>("TMPDIR", newTempDir.Path) },
async () =>
async () => await Task.Run(async () =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on why this change is needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I described the background in the linked issue. But in brief, ApplyEnvironmentVariables sets TMPDIR, runs the lambda, and then resets TMPDIR to its prior value. But it doesn't do any await on the function, and it seems that this means there's a race where sometimes TMPDIR is reset in the middle of executing the lambda - I've seen cases where the server was started with the new TMPDIR and then the client ran with the old TMPDIR. Since in the file lock model TMPDIR becomes part of the lock file name, server and client were then using two different lock files, causing failures.

{
using var serverData = await ServerUtil.CreateServer(_logger);
var result = RunCommandLineCompiler(
Expand All @@ -317,7 +317,7 @@ await ApplyEnvironmentVariables(

var listener = await serverData.Complete();
Assert.Equal(CompletionData.RequestCompleted, listener.CompletionDataList.Single());
});
}));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public async Task NoServerConnection()

var thread = new Thread(() =>
{
using (var mutex = new Mutex(initiallyOwned: true, name: mutexName, createdNew: out created))
using (var mutex = BuildServerConnection.OpenOrCreateMutex(name: mutexName, createdNew: out created))
using (var stream = NamedPipeUtil.CreateServer(pipeName))
{
readyMre.Set();
Expand All @@ -112,7 +112,7 @@ public async Task NoServerConnection()
stream.Close();

doneMre.WaitOne();
mutex.ReleaseMutex();
mutex.Dispose();
}
});

Expand Down Expand Up @@ -153,15 +153,14 @@ public async Task ServerShutdownsDuringProcessing()
{
using (var stream = NamedPipeUtil.CreateServer(pipeName))
{
var mutex = new Mutex(initiallyOwned: true, name: mutexName, createdNew: out created);
var mutex = BuildServerConnection.OpenOrCreateMutex(name: mutexName, createdNew: out created);
readyMre.Set();

stream.WaitForConnection();
connected = true;

// Client is waiting for a response. Close the mutex now. Then close the connection
// so the client gets an error.
mutex.ReleaseMutex();
mutex.Dispose();
stream.Close();

Expand Down
Loading