Skip to content

Commit

Permalink
Avoid bug during FUTDC validation after solution build completes
Browse files Browse the repository at this point in the history
In some cases (such as when FUTDC logging is enabled) we run a validation pass to report to the user when their projects appear out of date despite just having been built. This feature alerts users to overbuild and provides useful diagnostic information to correct it.

dotnet#9130 fixed a bug related to F5 builds. It introduced a race condition that can lead to the error reported in dotnet#9152.

Our `CurrentSolutionBuildContext` value is set when the SBM starts the solution build, and cleared to `null` when it completes.

Our validation logic runs async, and can complete after the SBM completes. In such cases, it can observe a null `CurrentSolutionBuildContext` value, which is not supported by the current code.

This change captures the `CurrentSolutionBuildContext` value early on to ensure it's non-null when we need it later on, and passes the specific value down, preventing any issues from null values.
  • Loading branch information
drewnoakes committed Jul 17, 2023
1 parent ebb70e2 commit 4aebcf6
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,9 @@ private bool CheckBuiltFromInputFiles(Log log, in TimestampCache timestampCache,
return true;
}

private bool CheckCopyToOutputDirectoryItems(Log log, UpToDateCheckImplicitConfiguredInput state, IEnumerable<(string Path, ImmutableArray<CopyItem> CopyItems)> copyItemsByProject, ConfiguredFileSystemOperationAggregator fileSystemAggregator, bool? isBuildAccelerationEnabled, CancellationToken token)
private bool CheckCopyToOutputDirectoryItems(Log log, UpToDateCheckImplicitConfiguredInput state, IEnumerable<(string Path, ImmutableArray<CopyItem> CopyItems)> copyItemsByProject, ConfiguredFileSystemOperationAggregator fileSystemAggregator, bool? isBuildAccelerationEnabled, SolutionBuildContext solutionBuildContext, CancellationToken token)
{
ITimestampCache? timestampCache = _solutionBuildContextProvider.CurrentSolutionBuildContext?.CopyItemTimestamps;

Assumes.NotNull(timestampCache);
ITimestampCache timestampCache = solutionBuildContext.CopyItemTimestamps;

string outputFullPath = Path.Combine(state.MSBuildProjectDirectory, state.OutputRelativeOrFullPath);

Expand Down Expand Up @@ -973,10 +971,12 @@ private async Task<bool> IsUpToDateInternalAsync(
//
// In either case, we construct an event here lazily so that we can correctly test for the
// existence of copy items in CheckCopyToOutputDirectoryItems.
if (_solutionBuildContextProvider.CurrentSolutionBuildContext is null)
SolutionBuildContext? solutionBuildContext = _solutionBuildContextProvider.CurrentSolutionBuildContext;
if (solutionBuildContext is null)
{
_solutionBuildEventListener.NotifySolutionBuildStarting();
Assumes.NotNull(_solutionBuildContextProvider.CurrentSolutionBuildContext);
solutionBuildContext = _solutionBuildContextProvider.CurrentSolutionBuildContext;
Assumes.NotNull(solutionBuildContext);
}

globalProperties.TryGetValue(FastUpToDateCheckIgnoresKindsGlobalPropertyName, out string? ignoreKindsString);
Expand Down Expand Up @@ -1083,7 +1083,7 @@ private async Task<bool> IsUpToDateInternalAsync(
!CheckInputsAndOutputs(logger, lastSuccessfulBuildStartTimeUtc, timestampCache, implicitState, ignoreKinds, token) ||
!CheckBuiltFromInputFiles(logger, timestampCache, implicitState, token) ||
!CheckMarkers(logger, timestampCache, implicitState, isBuildAccelerationEnabled, fileSystemOperations) ||
!CheckCopyToOutputDirectoryItems(logger, implicitState, copyInfo.ItemsByProject, configuredFileSystemOperations, isBuildAccelerationEnabled, token))
!CheckCopyToOutputDirectoryItems(logger, implicitState, copyInfo.ItemsByProject, configuredFileSystemOperations, isBuildAccelerationEnabled, solutionBuildContext, token))
{
return (false, checkedConfigurations);
}
Expand Down

0 comments on commit 4aebcf6

Please sign in to comment.