Skip to content

Remove the need for a global lock when building or publishing a project #21753

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

Merged
merged 1 commit into from
May 13, 2020
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
4 changes: 2 additions & 2 deletions src/ProjectTemplates/Shared/AspNetProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public AspNetProcess(
Timeout = TimeSpan.FromMinutes(2)
};

output.WriteLine("Running ASP.NET application...");
output.WriteLine("Running ASP.NET Core application...");

var arguments = published ? $"exec {dllPath}" : "run";
var arguments = published ? $"exec {dllPath}" : "run --no-build";

logger?.LogInformation($"AspNetProcess - process: {DotNetMuxer.MuxerPathOrDefault()} arguments: {arguments}");

Expand Down
2 changes: 1 addition & 1 deletion src/ProjectTemplates/Shared/ProcessLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ProcessLock(string name)

public async Task WaitAsync(TimeSpan? timeout = null)
{
timeout ??= TimeSpan.FromMinutes(2);
timeout ??= TimeSpan.FromMinutes(20);
Copy link
Contributor

Choose a reason for hiding this comment

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

That seems excessive...

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 know, but these used to wait indefinitely, so it's a minor improvement over that.

Copy link
Contributor

Choose a reason for hiding this comment

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

What goes wrong if they only wait 2 minutes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I added these timeouts here, the build passed a few times successfully on public AzDo, and promptly failed in the internal Azdo. This of course included the time it takes to build \ publish which is being changed here. What I'm going with here is that it's hard to pick a reasonable time, but we also do not want tests to fail just because restore took too long that one time.

Assert.True(await Semaphore.WaitAsync(timeout.Value), $"Unable to acquire process lock for process {Name}");
}

Expand Down
54 changes: 18 additions & 36 deletions src/ProjectTemplates/Shared/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,48 +109,30 @@ internal async Task<ProcessResult> RunDotNetNewAsync(
}
}

internal async Task<ProcessResult> RunDotNetPublishAsync(bool takeNodeLock = false, IDictionary<string, string> packageOptions = null, string additionalArgs = null)
internal async Task<ProcessResult> RunDotNetPublishAsync(IDictionary<string, string> packageOptions = null, string additionalArgs = null)
{
Output.WriteLine("Publishing ASP.NET application...");
Output.WriteLine("Publishing ASP.NET Core application...");

// This is going to trigger a build, so we need to acquire the lock like in the other cases.
// We want to take the node lock as some builds run NPM as part of the build and we want to make sure
// it's run without interruptions.
var effectiveLock = takeNodeLock ? new OrderedLock(NodeLock, DotNetNewLock) : new OrderedLock(nodeLock: null, DotNetNewLock);
await effectiveLock.WaitAsync();
try
{
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"publish -c Release /bl {additionalArgs}", packageOptions);
await result.Exited;
CaptureBinLogOnFailure(result);
return new ProcessResult(result);
}
finally
{
effectiveLock.Release();
}
// Avoid restoring as part of build or publish. These projects should have already restored as part of running dotnet new. Explicitly disabling restore
// should avoid any global contention and we can execute a build or publish in a lock-free way

using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"publish --no-restore -c Release /bl {additionalArgs}", packageOptions);
await result.Exited;
CaptureBinLogOnFailure(result);
return new ProcessResult(result);
}

internal async Task<ProcessResult> RunDotNetBuildAsync(bool takeNodeLock = false, IDictionary<string, string> packageOptions = null, string additionalArgs = null)
internal async Task<ProcessResult> RunDotNetBuildAsync(IDictionary<string, string> packageOptions = null, string additionalArgs = null)
{
Output.WriteLine("Building ASP.NET application...");
Output.WriteLine("Building ASP.NET Core application...");

// This is going to trigger a build, so we need to acquire the lock like in the other cases.
// We want to take the node lock as some builds run NPM as part of the build and we want to make sure
// it's run without interruptions.
var effectiveLock = takeNodeLock ? new OrderedLock(NodeLock, DotNetNewLock) : new OrderedLock(nodeLock: null, DotNetNewLock);
await effectiveLock.WaitAsync();
try
{
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"build -c Debug /bl {additionalArgs}", packageOptions);
await result.Exited;
CaptureBinLogOnFailure(result);
return new ProcessResult(result);
}
finally
{
effectiveLock.Release();
}
// Avoid restoring as part of build or publish. These projects should have already restored as part of running dotnet new. Explicitly disabling restore
// should avoid any global contention and we can execute a build or publish in a lock-free way

using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"build --no-restore -c Debug /bl {additionalArgs}", packageOptions);
await result.Exited;
CaptureBinLogOnFailure(result);
return new ProcessResult(result);
}

internal AspNetProcess StartBuiltProjectAsync(bool hasListeningUri = true, ILogger logger = null)
Expand Down