Skip to content

Commit

Permalink
[workloads] Add locks for parallel NuGet access (dotnet#7813)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pjcollins authored Sep 2, 2021
1 parent 923c95e commit 7168d63
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public string SuppressIces
set;
}

/// <summary>
/// Used to synchronize access to the NuGet being extracted.
/// </summary>
private readonly object extractNuGetLock = new object();

/// <summary>
/// Generate a set of MSIs for the specified platforms using the specified NuGet package.
/// </summary>
Expand All @@ -118,7 +123,11 @@ public string SuppressIces
/// <param name="platforms"></param>
protected IEnumerable<ITaskItem> 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<TaskItem> msis = new();

// MSI ProductName defaults to the package title and fallback to the package ID with a warning.
Expand All @@ -139,7 +148,10 @@ protected IEnumerable<ITaskItem> 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
{
Expand Down Expand Up @@ -188,9 +200,12 @@ protected IEnumerable<ITaskItem> 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
Expand Down

0 comments on commit 7168d63

Please sign in to comment.