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

[automated] Merge branch 'vs17.12' => 'main' #10749

Merged
merged 7 commits into from
Oct 4, 2024
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
47 changes: 46 additions & 1 deletion src/Build.UnitTests/BackEnd/BuildManager_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1657,13 +1657,14 @@ public void CancelledBuildWithDelay40()
string contents = CleanupFileContents(@"
<Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
<Target Name='test'>
<Exec Command='" + Helpers.GetSleepCommand(TimeSpan.FromSeconds(10)) + @"'/>
<Exec Command='" + Helpers.GetSleepCommand(TimeSpan.FromSeconds(20)) + @"'/>
<Message Text='[errormessage]'/>
</Target>
</Project>
");
BuildRequestData data = GetBuildRequestData(contents, Array.Empty<string>(), MSBuildDefaultToolsVersion);
_buildManager.BeginBuild(_parameters);
Stopwatch sw = Stopwatch.StartNew();
BuildSubmission asyncResult = _buildManager.PendBuildRequest(data);
asyncResult.ExecuteAsync(null, null);

Expand All @@ -1675,6 +1676,50 @@ public void CancelledBuildWithDelay40()

Assert.Equal(BuildResultCode.Failure, result.OverallResult); // "Build should have failed."
_logger.AssertLogDoesntContain("[errormessage]");
// The build should bail out immediately after executing CancelAllSubmissions, build stalling for a longer time
// is very unexpected.
sw.Elapsed.ShouldBeLessThan(TimeSpan.FromSeconds(10));
}

/// <summary>
/// A canceled build which waits for the task to get started before canceling. Because it is a 12.. task, we should
/// cancel the task and exit out after a short period wherein we wait for the task to exit cleanly.
///
/// This test also exercises the possibility of CancelAllSubmissions being executed after EndBuild -
/// which can happen even if they are synchronously executed in expected order - the CancelAllSubmissions is internally
/// asynchronous and hence part of the execution can happen after EndBuild.
/// </summary>
[Fact]
public void CancelledBuildWithDelay40_WithThreatSwap()
{
string contents = CleanupFileContents(@"
<Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
<Target Name='test'>
<Exec Command='" + Helpers.GetSleepCommand(TimeSpan.FromSeconds(20)) + @"'/>
<Message Text='[errormessage]'/>
</Target>
</Project>
");
BuildRequestData data = GetBuildRequestData(contents, Array.Empty<string>(), MSBuildDefaultToolsVersion);
_buildManager.BeginBuild(_parameters);
Stopwatch sw = Stopwatch.StartNew();
BuildSubmission asyncResult = _buildManager.PendBuildRequest(data);
asyncResult.ExecuteAsync(null, null);

Thread.Sleep(500);
// Simulate the case where CancelAllSubmissions is called after EndBuild or its internal queued task is swapped
// and executed after EndBuild starts execution.
System.Threading.Tasks.Task.Delay(500).ContinueWith(t => _buildManager.CancelAllSubmissions());
_buildManager.EndBuild();

asyncResult.WaitHandle.WaitOne();
BuildResult result = asyncResult.BuildResult;

Assert.Equal(BuildResultCode.Failure, result.OverallResult); // "Build should have failed."
_logger.AssertLogDoesntContain("[errormessage]");
// The build should bail out immediately after executing CancelAllSubmissions, build stalling for a longer time
// is very unexpected.
sw.Elapsed.ShouldBeLessThan(TimeSpan.FromSeconds(10));
}

/// <summary>
Expand Down
19 changes: 7 additions & 12 deletions src/Build/BackEnd/BuildManager/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -789,15 +789,10 @@ void Callback(object? state)
{
lock (_syncLock)
{
if (_shuttingDown)
{
return;
}

// If we are Idle, obviously there is nothing to cancel. If we are waiting for the build to end, then presumably all requests have already completed
// and there is nothing left to cancel. Putting this here eliminates the possibility of us racing with EndBuild to access the nodeManager before
// EndBuild sets it to null.
if (_buildManagerState != BuildManagerState.Building)
// If the state is Idle - then there is yet or already nothing to cancel
// If state is WaitingForBuildToComplete - we might be already waiting gracefully - but CancelAllSubmissions
// is a request for quick abort - so it's fine to resubmit the request
if (_buildManagerState == BuildManagerState.Idle)
{
return;
}
Expand Down Expand Up @@ -2078,17 +2073,17 @@ private void ShutdownConnectedNodes(bool abort)
lock (_syncLock)
{
_shuttingDown = true;
_executionCancellationTokenSource!.Cancel();
_executionCancellationTokenSource?.Cancel();

// If we are aborting, we will NOT reuse the nodes because their state may be compromised by attempts to shut down while the build is in-progress.
_nodeManager!.ShutdownConnectedNodes(!abort && _buildParameters!.EnableNodeReuse);
_nodeManager?.ShutdownConnectedNodes(!abort && _buildParameters!.EnableNodeReuse);

// if we are aborting, the task host will hear about it in time through the task building infrastructure;
// so only shut down the task host nodes if we're shutting down tidily (in which case, it is assumed that all
// tasks are finished building and thus that there's no risk of a race between the two shutdown pathways).
if (!abort)
{
_taskHostNodeManager!.ShutdownConnectedNodes(_buildParameters!.EnableNodeReuse);
_taskHostNodeManager?.ShutdownConnectedNodes(_buildParameters!.EnableNodeReuse);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Build/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Build/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/Build/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading