Merged PR 791949: [JavaScript] Fix race when adding spec file pip

The check for unique specs when adding JS pips had a potential race (even though a concurrent collection is used, the actual spec pip addition was happening outside a lock)

Related work items: #2189126
This commit is contained in:
Serge Mera 2024-06-26 01:18:06 +00:00
Родитель a96bf625c7
Коммит 2da7356fcb
1 изменённых файлов: 14 добавлений и 10 удалений

Просмотреть файл

@ -20,6 +20,7 @@ using BuildXL.Utilities.Core;
using BuildXL.Utilities.Collections;
using BuildXL.Utilities.Configuration;
using static BuildXL.Utilities.Core.FormattableStringEx;
using BuildXL.Utilities.Core.Tasks;
namespace BuildXL.FrontEnd.JavaScript
{
@ -56,7 +57,10 @@ namespace BuildXL.FrontEnd.JavaScript
private readonly ConcurrentBigMap<(JavaScriptProject, QualifierId), PipConstructionHelper> m_pipConstructionHelperPerProject = new ConcurrentBigMap<(JavaScriptProject, QualifierId), PipConstructionHelper>();
private readonly ConcurrentBigSet<AbsolutePath> m_specFilePips = new ConcurrentBigSet<AbsolutePath>();
/// <summary>
/// Used as a set. ConcurrentBigMap has a useful add factory (which the ConcurrentBigSet does not).
/// </summary>
private readonly ConcurrentBigMap<AbsolutePath, Unit> m_specFilePips = new ConcurrentBigMap<AbsolutePath, Unit>();
/// <summary>
/// Base directory where all logs are located
@ -579,15 +583,15 @@ namespace BuildXL.FrontEnd.JavaScript
// We shouldn't be adding the same spec file pip to the pip graph.
// This can happen if the same package root is defined for multiple packages, or if different qualifiers apply to the same package.
var result = m_specFilePips.GetOrAdd(pathToProject);
if (!result.IsFound)
{
m_frontEndHost.PipGraph?.AddSpecFile(
new SpecFilePip(
FileArtifact.CreateSourceFile(pathToProject),
new LocationData(pathToProject, 0, 0),
m_moduleDefinition.Descriptor.Id));
}
m_specFilePips.GetOrAdd(pathToProject, Unit.Void,
addValueFactory: (pathToProject, unit) => {
m_frontEndHost.PipGraph?.AddSpecFile(
new SpecFilePip(
FileArtifact.CreateSourceFile(pathToProject),
new LocationData(pathToProject, 0, 0),
m_moduleDefinition.Descriptor.Id));
return unit;
});
Root.TryGetRelative(PathTable, pathToProject, out var specRelativePath);
if (!PathAtom.TryCreate(m_context.StringTable, m_moduleDefinition.Descriptor.Name, out _))