diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md index 5ef93105656..d681f5aa1b7 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -1,5 +1,6 @@ ### Fixed +* Ensure `frameworkTcImportsCache` mutations are threadsafe. ([PR #17795](https://github.com/dotnet/fsharp/pull/17795)) ### Added diff --git a/src/Compiler/Service/IncrementalBuild.fs b/src/Compiler/Service/IncrementalBuild.fs index b7560b222c2..6b7f3c4d24d 100644 --- a/src/Compiler/Service/IncrementalBuild.fs +++ b/src/Compiler/Service/IncrementalBuild.fs @@ -507,10 +507,12 @@ type FrameworkImportsCache(size) = let frameworkTcImportsCache = AgedLookup>(size, areSimilar=(fun (x, y) -> x = y)) /// Reduce the size of the cache in low-memory scenarios - member _.Downsize() = frameworkTcImportsCache.Resize(AnyCallerThread, newKeepStrongly=0) + member _.Downsize() = lock gate <| fun () -> + frameworkTcImportsCache.Resize(AnyCallerThread, newKeepStrongly=0) /// Clear the cache - member _.Clear() = frameworkTcImportsCache.Clear AnyCallerThread + member _.Clear() = lock gate <| fun () -> + frameworkTcImportsCache.Clear AnyCallerThread /// This function strips the "System" assemblies from the tcConfig and returns a age-cached TcImports for them. member _.GetNode(tcConfig: TcConfig, frameworkDLLs: AssemblyResolution list, nonFrameworkResolutions: AssemblyResolution list) =