Skip to content

Commit f68e13b

Browse files
Copilotradicalmitchdenny
authored
Fix thread safety issue in FindAppHostProjectFilesAsync by switching to ConcurrentBag (#9655)
* Initial plan for issue * Fix thread safety issue in FindAppHostProjectFilesAsync using ConcurrentBag Co-authored-by: radical <1472+radical@users.noreply.github.com> * Remove debugging output line as requested in code review Co-authored-by: radical <1472+radical@users.noreply.github.com> * Revert test file changes as requested in code review Co-authored-by: radical <1472+radical@users.noreply.github.com> * Switch from ConcurrentBag to List with locking as requested in code review Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: radical <1472+radical@users.noreply.github.com> Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>
1 parent adcb160 commit f68e13b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Aspire.Cli/Projects/ProjectLocator.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ private async Task<List<FileInfo>> FindAppHostProjectFilesAsync(DirectoryInfo se
2525
return await interactionService.ShowStatusAsync("Searching", async () =>
2626
{
2727
var appHostProjects = new List<FileInfo>();
28+
var lockObject = new object();
2829
logger.LogDebug("Searching for project files in {SearchDirectory}", searchDirectory.FullName);
2930
var enumerationOptions = new EnumerationOptions
3031
{
@@ -52,7 +53,10 @@ await Parallel.ForEachAsync(projectFiles, async (projectFile, ct) =>
5253
logger.LogDebug("Found AppHost project file {ProjectFile} in {SearchDirectory}", projectFile.FullName, searchDirectory.FullName);
5354
var relativePath = Path.GetRelativePath(currentDirectory.FullName, projectFile.FullName);
5455
interactionService.DisplaySubtleMessage(relativePath);
55-
appHostProjects.Add(projectFile);
56+
lock (lockObject)
57+
{
58+
appHostProjects.Add(projectFile);
59+
}
5660
}
5761
else
5862
{

0 commit comments

Comments
 (0)