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

[17.11] Prevent contention between CancelAllSubmissions and EndBuild #10743

Closed
Closed
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
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the MIT license. See License.txt in the project root for full license information. -->
<Project>
<PropertyGroup>
<VersionPrefix>17.11.10</VersionPrefix><DotNetFinalVersionKind>release</DotNetFinalVersionKind>
<VersionPrefix>17.11.11</VersionPrefix><DotNetFinalVersionKind>release</DotNetFinalVersionKind>
<PackageValidationBaselineVersion>17.10.4</PackageValidationBaselineVersion>
<AssemblyVersion>15.1.0.0</AssemblyVersion>
<PreReleaseVersionLabel>servicing</PreReleaseVersionLabel>
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 @@ -792,15 +792,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 attempt again here
if (_buildManagerState == BuildManagerState.Idle)
{
return;
}
Expand Down Expand Up @@ -2094,17 +2089,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