Repository navigation
Fix NativeAOT tool build race in NativeAot.Tests - #67320
Conversation
The test project references aspnetcoretools with Targets=Build and explicit RuntimeIdentifier/TargetRuntimeIdentifier global properties. Those globals differ from the global property set the solution traversal uses to build the same project (TargetFramework only, no RID), so MSBuild treats them as two distinct builds and NativeAOT-compiles aspnetcoretools twice concurrently. The two ilc processes race on the shared intermediate file artifacts/obj/.../native/aspnetcoretools.sourcelink, intermittently failing with an IOException (file in use) and breaking the Build Tests Helix legs. Build the reference with the same TargetFramework-only global properties as the traversal so MSBuild dedupes onto that single build, eliminating the second compile and the race while preserving the build-ordering dependency. The published RID is unchanged: it is still resolved by the standalone build (and the test's NativeAotToolPublishRoot glob) from RuntimeIdentifier/TargetRuntimeIdentifier/ NETCoreSdkRuntimeIdentifier, so repo and VMR (cross-RID) builds are unaffected. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR addresses intermittent Helix Build Tests failures in NativeAot.Tests caused by two concurrent, differently-keyed MSBuild builds of the aspnetcoretools NativeAOT aggregate tool racing on a shared intermediate .sourcelink file. It aligns the ProjectReference global properties with the solution traversal build so MSBuild can deduplicate the build and avoid running multiple simultaneous NativeAOT compiles.
Changes:
- Updates the test project’s
ProjectReferenceto buildaspnetcoretoolsusingTargetFrameworkonly (removing explicitRuntimeIdentifier/TargetRuntimeIdentifierglobals). - Expands the inline comment to document the MSBuild global-properties deduping rationale and the race being avoided.
|
@wtgodbe is this in addition to the changes that were made in the VMR when the aggregated native shims were enabled? |
Can you point me to those changes? I believe it is, anything that was merged into the VMR before yesterday-ish should now be in aspnetcore |
OK, when we re-landed the aggregate executable shims last week that had a bunch of changes to try and fix these races, based on what was done in |
Yeah, in my experience these races are very annoying to try to pin down and fix. dotnet/msbuild#13599 is related |
…67327) PR #67320 attempted to fix the intermittent ILC sourcelink file lock (aspnetcoretools.sourcelink 'being used by another process') by changing the NativeAot.Tests ProjectReference to pass Properties="TargetFramework=$(DefaultNetCoreTargetFramework)". That was insufficient: the solution traversal builds the single-targeted aspnetcoretools.csproj with NO TargetFramework global property, so passing TargetFramework=net11.0 still produces a differently-keyed MSBuild project instance. The two instances both run a NativeAOT compile concurrently and race on the shared intermediate sourcelink file. Drop the explicit property and UndefineProperties TargetFramework and RuntimeIdentifier so this reference resolves to the same project instance the traversal builds and dedupes onto it. Co-authored-by: Copilot <[email protected]>
Problem
The Build Tests Helix legs intermittently fail with:
aspnetcoretools(the NativeAOT aggregate tool) is built twice concurrently:{ ..., TargetFramework=net11.0 }(no RID).Microsoft.AspNetCore.Tools.NativeAot.Tests.csproj'sProjectReference, which passed explicitRuntimeIdentifier/TargetRuntimeIdentifierglobals (noTargetFramework).Because MSBuild caches project results by
(project, global properties), the two differing global-property sets are treated as separate builds, so twoilcprocesses NativeAOT-compile the project at the same time and race on the shared intermediate.sourcelinkfile. The failure is transient — it only fails when the twoIlcCompilewindows overlap.Fix
Build the reference with the same global properties the traversal uses (
TargetFrameworkonly, no explicit RID). MSBuild then dedupes the reference onto the traversal's single build instead of spawning a second compile, eliminating the race while keeping the build-ordering dependency that ensures the tool is published before the test gathers its Helix payload.The published RID is unchanged: it is still resolved by the standalone build (and by the test's
NativeAotToolPublishRootglob) viaRuntimeIdentifier→TargetRuntimeIdentifier→NETCoreSdkRuntimeIdentifier, so both the normal repo build and the VMR (cross-RID) build resolve the same RID as before.