microsoft / MSBuildSdks

MSBuild project SDKs
MIT License
454 stars 81 forks source link

Microsoft.Build.CopyOnWrite sometimes errors on build hosts #546

Closed cg110 closed 6 months ago

cg110 commented 6 months ago

Hi,

We've added CopyOnWrite to our builds, but every so often our build servers get an exception while trying to initialize the task, which I believe is some kind of volume has been removed/isn't accessible.

  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061: The "Copy" task could not be instantiated from "C:\Users\svc_build\.nuget\packages\microsoft.build.copyonwrite\1.0.302\build\netstandard2.0\Microsoft.Build.CopyOnWrite.dll".
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061: System.TypeInitializationException: The type initializer for 'Microsoft.Build.Tasks.Copy' threw an exception.
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:  ---> System.IO.FileNotFoundException: Failed retrieving volume information for \\?\Volume{105aac29-84e5-4492-934a-0d99cbe7d212}\\ with winerror 2
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:    at Microsoft.CopyOnWrite.Windows.NativeMethods.ThrowSpecificIoException(Int32 lastErr, String message) in D:\CoW\lib\Windows\NativeMethods.cs:line 30
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:    at Microsoft.CopyOnWrite.Windows.VolumeInfoCache.GetVolumeInfo(VolumePaths volumePaths) in D:\CoW\lib\Windows\VolumeInfoCache.cs:line 141
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:    at Microsoft.CopyOnWrite.Windows.VolumeInfoCache.BuildFromCurrentFilesystem() in D:\CoW\lib\Windows\VolumeInfoCache.cs:line 36
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:    at Microsoft.CopyOnWrite.Windows.WindowsCopyOnWriteFilesystem..ctor() in D:\CoW\lib\Windows\WindowsCopyOnWriteFilesystem.cs:line 24
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:    at Microsoft.CopyOnWrite.CopyOnWriteFilesystemFactory.Create() in D:\CoW\lib\CopyOnWriteFilesystemFactory.cs:line 48
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:    at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:    at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:    at System.Lazy`1.CreateValue()
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:    at Microsoft.CopyOnWrite.CopyOnWriteFilesystemFactory.GetInstance() in D:\CoW\lib\CopyOnWriteFilesystemFactory.cs:line 22
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:    at Microsoft.Build.Tasks.Copy..cctor()
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:    --- End of inner exception stack trace ---
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:    at Microsoft.Build.Tasks.Copy..ctor()
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4061:    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
  dotnet\sdk\8.0.203\Microsoft.Common.CurrentVersion.targets(4967,5): error MSB4060: The "Copy" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.

I'm not sure if there's an error case that needs better handling so that the code assumes it shouldn't do COW on a volume it can't find. (We may simply disable CoW for our windows build servers, as they're not using ReFS so don't benefit from the nuget anyway).

Thanks, Chris

erikmav commented 6 months ago

Thanks for the bug report. Agreed this is a case to fix in the CoW library. I'll get started on a fix ASAP.

erikmav commented 6 months ago

The following SDK package versions have been released to nuget.org with a fix:

Please give them a try.

cg110 commented 6 months ago

Thanks for the quick response, I'll update (but given the rarity it's likely a fix that'll be hard to prove is fixed other than it not occurring)

erikmav commented 6 months ago

Didn't hear back after 3 weeks, closing this as completed. Please reopen if you hit the problem again.

cg110 commented 6 months ago

Hi,

I'm not aware of any of our builds having the problem since updating to the fixed version.

So very much seems fixed.

Thanks Chris