dotnet / dotnet/msbuild

Graph based cache builds fail with cache aggregation error on isolation exempt shared projects

Open
#4,885 0 comments 0 reactions 0 assignees View on GitHub
bug triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 6h
Merged PRs (30d)
139

Description

### Steps to reproduce

Do a graph based cache based build on the zipped repro:
[isolationExemptBug.zip](https://github.com/microsoft/msbuild/files/3806827/isolationExemptBug.zip)

Command line (using the test script from https://github.com/microsoft/MSBuildStaticGraphTester/blob/master/scripts/Test.ps1)
```
.\scripts\Build.ps1 -BuildRepos
.\scripts\Test.ps1 -singleProjectDirectory E:\delete\isolationExemptBug\ -singleProjectEntryFile E:\delete\isolationExemptBug\1\1.proj -includeMSBuildTests
```
### Expected behavior
Both builds succeed

### Actual behavior
The cache roundtrip test fails with
```
================================================================================================
=========================Cache roundtrip: E:\delete\isolationExemptBug\=========================
================================================================================================
Loading graph from solution E:\delete\isolationExemptBug\1\1.proj
Root Count: 1
Node Count: 3
Build started 11/4/2019 5:31:37 PM.
Using input build results caches:
Writing build results caches to: E:\delete\isolationExemptBug\\caches\3-54444047
__________________________________________________
Project "E:\delete\isolationExemptBug\3\3.proj" (Build target(s)):

Target Undeclared:
MSB4260: Project "E:\delete\isolationExemptBug\3\3.proj" skipped graph isolation constraints on referenced project "E:\delete\isolationExemptBug\4\4.proj"
__________________________________________________
Project "E:\delete\isolationExemptBug\3\3.proj" is building "E:\delete\isolationExemptBug\4\4.proj" (Build target(s)):

Target Build:
Hello 4

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:00.41
Build started 11/4/2019 5:31:38 PM.
Using input build results caches:
Writing build results caches to: E:\delete\isolationExemptBug\\caches\2-34640832
__________________________________________________
Project "E:\delete\isolationExemptBug\2\2.proj" (Build target(s)):

Target Undeclared:
MSB4260: Project "E:\delete\isolationExemptBug\2\2.proj" skipped graph isolation constraints on referenced project "E:\delete\isolationExemptBug\4\4.proj"
__________________________________________________
Project "E:\delete\isolationExemptBug\2\2.proj" is building "E:\delete\isolationExemptBug\4\4.proj" (Build target(s)):

Target Build:
Hello 4

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:00.01
Build started 11/4/2019 5:31:38 PM.
Using input build results caches: E:\delete\isolationExemptBug\\caches\2-34640832;E:\delete\isolationExemptBug\\caches\3-54444047

Unhandled Exception: Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: Input caches should not contain entries for the same configuration
at Microsoft.Build.Shared.ErrorUtilities.ThrowInternalError(String message, Exception innerException, Object[] args) in E:\projects\MSBuildStaticGraphTester\repo\MSBuild\src\Shared\ErrorUtilities.cs:line 70
at Microsoft.Build.Execution.CacheAggregator.InsertCaches(IConfigCache configCache, IResultsCache resultsCache) in E:\projects\MSBuildStaticGraphTester\repo\MSBuild\src\Build\BackEnd\BuildManager\CacheAggregator.cs:line 75
at Microsoft.Build.Execution.CacheAggregator.Aggregate() in E:\projects\MSBuildStaticGraphTester\repo\MSBuild\src\Build\BackEnd\BuildManager\CacheAggregator.cs:line 48
at Microsoft.Build.Execution.BuildManager.ReuseOldCaches(String[] inputCacheFiles) in E:\projects\MSBuildStaticGraphTester\repo\MSBuild\src\Build\BackEnd\BuildManager\BuildManager.cs:line 2461
at Microsoft.Build.Execution.BuildManager.g__InitializeCaches|53_1() in E:\projects\MSBuildStaticGraphTester\repo\MSBuild\src\Build\BackEnd\BuildManager\BuildManager.cs:line 477
at Microsoft.Build.Execution.BuildManager.BeginBuild(BuildParameters parameters) in E:\projects\MSBuildStaticGraphTester\repo\MSBuild\src\Build\BackEnd\BuildManager\BuildManager.cs:line 405
at Microsoft.Build.Execution.BuildManager.Build(BuildParameters parameters, BuildRequestData requestData) in E:\projects\MSBuildStaticGraphTester\repo\MSBuild\src\Build\BackEnd\BuildManager\BuildManager.cs:line 816
at msb.Program.BuildProject(String projectInstanceFullPath, IDictionary`2 globalProperties, IReadOnlyCollection`1 entryTargets, String[] inputCachesFiles, String outputCacheFile) in E:\projects\MSBuildStaticGraphTester\src\msb\Program.cs:line 411
at msb.Program.BuildGraphWithCacheFileRoundtrip(IReadOnlyCollection`1 projectFiles, String cacheRoot) in E:\projects\MSBuildStaticGraphTester\src\msb\Program.cs:line 332
at msb.Program.BuildWithCacheRoundtrip(IReadOnlyList`1 args) in E:\projects\MSBuildStaticGraphTester\src\msb\Program.cs:line 275
at msb.Program.Main(String[] args) in E:\projects\MSBuildStaticGraphTester\src\msb\Program.cs:line 141
```

### Probable cause
A project's reference can be excluded from graph isolation constraint checks by adding it to a `GraphIsolationExemptReference` item. When multiple projects exempt a shared project, the build results from the exempt project leak into the output results cache and cause a cache aggregation failure on a depending project.

For example, given the graph:
`1 -> 2, 3`
With projects 2 and 3 exempting an unknown-to-the-graph project `4`.

Both projects `2` and `3` will build `4`, and both will include `4`'s results in their caches. Project 1 then tries to aggregate the output caches from `2` and `3`, and blows up.

A potential fix could be to avoid writing `4`'s results to the results cache. It has been exempt from isolation constraints, and maybe it should be invisible to the build as well. The `GraphIsolationExemptReference` feature was introduced to exempt the build-time generated xaml projects, but those projects don't get shared, so everything was fine with them.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.