msbuild: [Bug]: File copy is no longer retried, causing builds to randomly fail
Issue Description
We started receiving random build failures caused by failing file copy operations:
C:\Program Files\dotnet\sdk\7.0.400\Microsoft.Common.CurrentVersion.targets(4879,5): error MSB3021: Unable to copy file “C:\Program Files\Unity\Hub\Editor\2021.3.26f1\Editor\Data\Managed\UnityEngine\UnityEngine.UnityCurlModule.dll” to “Temp\Bin\Debug\Unity.Rider.Editor\UnityEngine.UnityCurlModule.dll”. Access to the path ‘C:\jenkins\workspace\Temp\Bin\Debug\Unity.Rider.Editor\UnityEngine.UnityCurlModule.dll’ is denied. [C:\jenkins\workspace\<redacted>.csproj]
After investigating we found that this is caused by a regression between .NET SDK 7.0.306 (MSBuild version 17.6.8+c70978d4d for .NET) and 7.0.400 (MSBuild version 17.7.1+971bf70db for .NET). The older version worked around this by doing a retry:
C:\Program Files\dotnet\sdk\7.0.306\Microsoft.Common.CurrentVersion.targets(4862,5): warning MSB3026: Could not copy “C:\Program Files\Unity\Hub\Editor\2021.3.26f1\Editor\Data\Managed\UnityEngine\UnityEditor.SceneTemplateModule.xml” to “Temp\Bin\Debug\Unity.Rider.Editor\UnityEditor.SceneTemplateModule.xml”. Beginning retry 1 in 1000ms. The process cannot access the file ‘C:\jenkins\workspace\Temp\Bin\Debug\Unity.Rider.Editor\UnityEditor.SceneTemplateModule.xml’ because it is being used by another process. [C:\jenkins\workspace\<redacted>.csproj]
The new version fails right away if there is already a retry queued:
[2023-08-24T08:22:18.186Z] C:\Program Files\dotnet\sdk\7.0.400\Microsoft.Common.CurrentVersion.targets(4879,5): warning MSB3026: Could not copy "C:\Program Files\Unity\Hub\Editor\2021.3.26f1\Editor\Data\Managed\UnityEngine\UnityEditor.CoreModule.xml" to "Temp\Bin\Debug\Unity.Rider.Editor\UnityEditor.CoreModule.xml". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\jenkins\workspace\Temp\Bin\Debug\Unity.Rider.Editor\UnityEditor.CoreModule.xml' because it is being used by another process. [C:\jenkins\workspace\redacted2.csproj]
[2023-08-24T08:22:18.186Z] C:\Program Files\dotnet\sdk\7.0.400\Microsoft.Common.CurrentVersion.targets(4879,5): error MSB3021: Unable to copy file "C:\Program Files\Unity\Hub\Editor\2021.3.26f1\Editor\Data\Managed\UnityEngine\UnityEditor.CoreModule.xml" to "Temp\Bin\Debug\Unity.Rider.Editor\UnityEditor.CoreModule.xml". Access to the path 'C:\jenkins\workspace\Temp\Bin\Debug\Unity.Rider.Editor\UnityEditor.CoreModule.xml' is denied. [C:\jenkins\workspace\redacted1.csproj]
Note that in the logs above the two lines are logged for different projects.
Steps to Reproduce
Build a large project that references many of the same files. Exact details or minimal repro project is not provided because root cause has been identified above.
Expected Behavior
File copy operations should be retried
Actual Behavior
File copy operations are not retried and fail
Analysis
Relevant logs:
[2023-08-24T08:22:07.879Z] MSBuild version 17.7.1+971bf70db for .NET
[2023-08-24T08:22:08.081Z] Build started 8/24/2023 8:22:08 AM.
[2023-08-24T08:22:08.384Z] 1>Project "C:\jenkins\workspace\redacted.sln" on node 1 (Clean target(s)).
[2023-08-24T08:22:08.384Z] 1>ValidateSolutionConfiguration:
[2023-08-24T08:22:08.384Z] Building solution configuration "Debug|Any CPU".
[2023-08-24T08:22:08.585Z] 1>Project "C:\jenkins\workspace\redacted.sln" (1) is building "C:\jenkins\workspace\redacted.csproj" (2) on node 1 (Clean target(s)).
[2023-08-24T08:22:08.586Z] 2>CoreClean:
[2023-08-24T08:22:08.586Z] Creating directory "obj\Debug\".
[2023-08-24T08:22:08.687Z] 2>Done Building Project "C:\jenkins\workspace\redacted.csproj" (Clean target(s)).
[2023-08-24T08:22:09.846Z] 1>Done Building Project "C:\jenkins\workspace\redacted.sln" (Clean target(s)).
[2023-08-24T08:22:09.846Z]
[2023-08-24T08:22:09.846Z] Build succeeded.
[2023-08-24T08:22:09.846Z] 0 Warning(s)
[2023-08-24T08:22:09.846Z] 0 Error(s)
[2023-08-24T08:22:09.846Z]
[2023-08-24T08:22:09.846Z] Time Elapsed 00:00:01.80
[2023-08-24T08:22:10.249Z] SonarScanner for MSBuild 5.13
[2023-08-24T08:22:10.249Z] Using the .NET Core version of the Scanner for MSBuild
...
[2023-08-24T08:22:18.185Z] C:\Program Files\dotnet\sdk\7.0.400\Microsoft.Common.CurrentVersion.targets(4879,5): warning MSB3026: Could not copy "C:\Program Files\Unity\Hub\Editor\2021.3.26f1\Editor\Data\Managed\UnityEngine\UnityEngine.UnityWebRequestModule.dll" to "Temp\Bin\Debug\Unity.Rider.Editor\UnityEngine.UnityWebRequestModule.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\jenkins\workspace\Temp\Bin\Debug\Unity.Rider.Editor\UnityEngine.UnityWebRequestModule.dll' because it is being used by another process. [C:\jenkins\workspace\redacted2.csproj]
[2023-08-24T08:22:18.185Z] C:\Program Files\dotnet\sdk\7.0.400\Microsoft.Common.CurrentVersion.targets(4879,5): warning MSB3026: Could not copy "C:\Program Files\Unity\Hub\Editor\2021.3.26f1\Editor\Data\Managed\UnityEngine\UnityEngine.PhysicsModule.xml" to "Temp\Bin\Debug\Unity.Rider.Editor\UnityEngine.PhysicsModule.xml". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\jenkins\workspace\Temp\Bin\Debug\Unity.Rider.Editor\UnityEngine.PhysicsModule.xml' because it is being used by another process. [C:\jenkins\workspace\redacted1.csproj]
[2023-08-24T08:22:18.186Z] CSC : warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. [C:\jenkins\workspace\Yousician.Analytics.Yap.Tests.csproj]
[2023-08-24T08:22:18.186Z] Sonar: (UniRx.csproj) Project processed successfully
[2023-08-24T08:22:18.186Z] C:\Program Files\dotnet\sdk\7.0.400\Microsoft.Common.CurrentVersion.targets(4879,5): warning MSB3026: Could not copy "C:\Program Files\Unity\Hub\Editor\2021.3.26f1\Editor\Data\Managed\UnityEngine\UnityEditor.CoreModule.xml" to "Temp\Bin\Debug\Unity.Rider.Editor\UnityEditor.CoreModule.xml". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\jenkins\workspace\Temp\Bin\Debug\Unity.Rider.Editor\UnityEditor.CoreModule.xml' because it is being used by another process. [C:\jenkins\workspace\redacted2.csproj]
[2023-08-24T08:22:18.186Z] CSC : warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. [C:\jenkins\workspace\Yousician.Networking.Tests.csproj]
[2023-08-24T08:22:18.186Z] CSC : warning CS2008: No source files specified. [C:\jenkins\workspace\redacted.csproj]
[2023-08-24T08:22:18.186Z] C:\Program Files\dotnet\sdk\7.0.400\Microsoft.Common.CurrentVersion.targets(4879,5): error MSB3021: Unable to copy file "C:\Program Files\Unity\Hub\Editor\2021.3.26f1\Editor\Data\Managed\UnityEngine\UnityEditor.CoreModule.xml" to "Temp\Bin\Debug\Unity.Rider.Editor\UnityEditor.CoreModule.xml". Access to the path 'C:\jenkins\workspace\Temp\Bin\Debug\Unity.Rider.Editor\UnityEditor.CoreModule.xml' is denied. [C:\jenkins\workspace\redacted1.csproj]
...
[2023-08-24T08:22:54.586Z] C:\Program Files\dotnet\sdk\7.0.400\Microsoft.Common.CurrentVersion.targets(4879,5): error MSB3021: Unable to copy file "C:\Program Files\Unity\Hub\Editor\2021.3.26f1\Editor\Data\Managed\UnityEngine\UnityEditor.CoreModule.xml" to "Temp\Bin\Debug\Unity.Rider.Editor\UnityEditor.CoreModule.xml". Access to the path 'C:\jenkins\workspace\Temp\Bin\Debug\Unity.Rider.Editor\UnityEditor.CoreModule.xml' is denied. [C:\jenkins\workspace\redacted1.csproj]
[2023-08-24T08:22:54.586Z] 12614 Warning(s)
[2023-08-24T08:22:54.586Z] 1 Error(s)
[2023-08-24T08:22:54.586Z]
[2023-08-24T08:22:54.586Z] Time Elapsed 00:00:42.18
Versions & Configurations
MSBuild version 17.7.1+971bf70db for .NET
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (6 by maintainers)
I am not sure if there is a follow up with this issue. We have workaround, and without repro or process monitor log we don’t know how to detect this transient file access issue. We can consider MSBUILDALWAYSRETRY as default behavior but it will make build with wrong user entered path took longer before fail. I recommend to lower priority of this to P3. @rainersigwald @YuliiaKovalova do you agree?
I’m not sure what causes it, but
export MSBUILDALWAYSRETRY=1resolved the issue completely.The log looks like each file got ERROR_SHARING_VIOLATION initially but ERROR_ACCESS_DENIED on the retry. src/Tasks/Copy.cs does not normally retry after ERROR_ACCESS_DENIED but this can be changed via the MSBUILDALWAYSRETRY environment variable. I don’t see any obvious change in this logic between 17.6.8+c70978d4d and 17.7.1+971bf70db, though.