From 7168d631952ce619c8b685e57e4486b9029cde4f Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Thu, 2 Sep 2021 09:51:04 -0400 Subject: [PATCH] [workloads] Add locks for parallel NuGet access (#7813) Android workload pack conversion has been failing intermittently: Generating package project: 'obj\Debug\src\msiPackage\x86\Microsoft.Android.Sdk.Windows\msi.csproj' convert.proj(72,5): error : One or more errors occurred. convert.proj(72,5): error : Failed to generate MSIs for workload packs. C:\Users\AzDevOps\.nuget\packages\wix\3.14.0-dotnet\tools\heat.exe dir obj\Debug\pkg\Microsoft.Android.Templates.31.0.100-rc.2.14 -cg CG_PackageContent -var var.SourceDir -ag -srd -sreg -dr InstallDir -o obj\Debug\src\msi\Microsoft.Android.Templates\31.0.100-rc.2.14\x64\PackageContent.wxs ##[error]light.exe(0,0): Error LGHT0001: The system cannot find the file specified. (Exception from HRESULT: 0x80070002) light.exe : error LGHT0001: The system cannot find the file specified. (Exception from HRESULT: 0x80070002) [C:\a\1\s\nuget-msi-convert\convert-v2\convert.proj] Exception Type: System.IO.FileNotFoundException Stack Trace: at Microsoft.Tools.WindowsInstallerXml.Cab.Interop.NativeMethods.CreateCabFinish(IntPtr contextHandle, IntPtr newCabNamesCallBackAddress) at Microsoft.Tools.WindowsInstallerXml.Cab.WixCreateCab.Complete(IntPtr newCabNamesCallBackAddress) at Microsoft.Tools.WindowsInstallerXml.CabinetBuilder.CreateCabinet(CabinetWorkItem cabinetWorkItem) at Microsoft.Tools.WindowsInstallerXml.CabinetBuilder.ProcessWorkItems() I've added a lock to attempt to synchronize some .nupkg file access that seemed to be problematic when executing asynchronously. --- .../src/GenerateMsiBase.cs | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs index c139e72dc51..11b7560fa4b 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs +++ b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs @@ -110,6 +110,11 @@ public string SuppressIces set; } + /// + /// Used to synchronize access to the NuGet being extracted. + /// + private readonly object extractNuGetLock = new object(); + /// /// Generate a set of MSIs for the specified platforms using the specified NuGet package. /// @@ -118,7 +123,11 @@ public string SuppressIces /// protected IEnumerable Generate(string sourcePackage, string swixPackageId, string outputPath, WorkloadPackKind kind, params string[] platforms) { - NugetPackage nupkg = new(sourcePackage, Log); + NugetPackage nupkg = null; + lock (extractNuGetLock) + { + nupkg = new(sourcePackage, Log); + } List msis = new(); // MSI ProductName defaults to the package title and fallback to the package ID with a warning. @@ -139,7 +148,10 @@ protected IEnumerable Generate(string sourcePackage, string swixPacka if ((kind != WorkloadPackKind.Library) && (kind != WorkloadPackKind.Template)) { Log.LogMessage(MessageImportance.Low, $"Extracting '{sourcePackage}' to '{packageContentsDirectory}'"); - nupkg.Extract(packageContentsDirectory, exclusions); + lock (extractNuGetLock) + { + nupkg.Extract(packageContentsDirectory, exclusions); + } } else { @@ -188,9 +200,12 @@ protected IEnumerable Generate(string sourcePackage, string swixPacka SourceDirectory = packageContentsDirectory }; - if (!heat.Execute()) + lock (extractNuGetLock) { - throw new Exception($"Failed to harvest package contents."); + if (!heat.Execute()) + { + throw new Exception($"Failed to harvest package contents."); + } } // Compile the MSI sources