Repository navigation
Description
Description
Running dotnet outdated --recursive -fba -u can crash when analyzing multiple file-based apps. The failure is timing-dependent: rerunning the command may succeed, and a directive may already have been updated before the process crashes.
Environment
- Windows
- dotnet-outdated 4.8.1 (
9730dd4f48fe1df7e30f35a0c6ed826107f4a547) - .NET SDK 11.0.100-rc.1.26425.128
- Observed in the
DamianEdwards/runfilerepository on itsrefbranch
Reproduction
-
Use a directory containing multiple file-based apps, including an app with an outdated SDK directive such as
#:sdk [email protected]. -
Run:
dotnet outdated --recursive -fba -u
-
Depending on concurrent analysis timing, the command can crash while upgrading a dependency.
This is not a deterministic reproduction. In the observed run, the crash occurred while upgrading Aspire.AppHost.Sdk from 13.3.3 to 13.5.3.
Expected behavior
Parallel project analysis and subsequent upgrades should complete without corrupting internal caches or throwing an unhandled exception.
Actual behavior
The SDK directive was updated on disk, but cache invalidation then crashed:
Upgrading package Aspire.AppHost.Sdk...
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'fileName')
at System.IO.FileInfo..ctor(String fileName)
at System.IO.Abstractions.FileInfoFactory.New(String fileName)
at DotNetOutdated.Core.Services.VariableTrackingService.<>c__DisplayClass12_0.<InvalidateCache>b__0(String key)
at System.Linq.Enumerable.IEnumerableWhereIterator`1.ToList()
at DotNetOutdated.Core.Services.VariableTrackingService.InvalidateCache(String propertyFilePath, String packageRefFilePath)
at DotNetOutdated.Core.Services.VariableTrackingService.UpdateFileBasedAppDirectReference(String projectFilePath, String name, FileBasedAppReferenceKind kind, NuGetVersion newVersion)
at DotNetOutdated.Core.Services.DotNetPackageService.AddPackage(String projectPath, String packageName, String frameworkName, NuGetVersion version, Boolean noRestore, Boolean ignoreFailedSources)
at DotNetOutdated.Program.UpgradePackages(List`1 projects, IConsole console)
Root cause and proposed fix
Parallel project analysis shares a VariableTrackingService, whose variable and file-based-app scan caches use non-thread-safe dictionaries. Concurrent writes can corrupt their state; the null key encountered during invalidation is a downstream symptom.
The concurrency regression in #788 reproduced dictionary corruption before the fix. That PR changes both caches to ConcurrentDictionary, uses TryRemove for invalidation, and adds coverage for subsequent updates. The reporter manually verified the fixed build against the original repository.
Related fix: #788.
Activity