Skip to content

Commit 018bb1e

Browse files
committed
fix: paket manager race condition
1 parent 3f10e5a commit 018bb1e

File tree

9 files changed

+72
-53
lines changed

9 files changed

+72
-53
lines changed

src/Queil.FSharp.DependencyManager.Paket/PaketDependencyManager.fs

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,41 @@ type ResolveDependenciesResult
3434
member _.Roots = roots
3535

3636
type Configuration =
37-
{ Verbose: bool
37+
{ IsDefault: bool
38+
Verbose: bool
3839
Logger: (string -> unit) option
3940
OutputRootDir: string
4041
ScriptOutputRootDir: string option
4142
ScriptOutputVersionDir: string option }
4243

43-
module Configure =
44-
let mutable private data =
45-
46-
let outputRootDir = Path.Combine(Path.GetTempPath(), ".fsch")
47-
48-
{ Verbose = false
44+
static member Default =
45+
{ IsDefault = true
46+
Verbose = false
4947
Logger = None
50-
OutputRootDir = outputRootDir
48+
OutputRootDir = Path.Combine(Path.GetTempPath(), ".fsch")
5149
ScriptOutputRootDir = None
5250
ScriptOutputVersionDir = None }
5351

54-
let private lockObj = obj ()
52+
module Configure =
53+
54+
let private data: ConcurrentDictionary<string, Configuration> =
55+
ConcurrentDictionary<string, Configuration>()
56+
57+
let update (key: string) (update: Configuration -> Configuration) : unit =
58+
59+
data.AddOrUpdate(
60+
key,
61+
(fun _ ->
62+
{ update Configuration.Default with
63+
IsDefault = false }),
64+
(fun _ old -> { update old with IsDefault = false })
65+
)
5566

56-
let update f = lock lockObj (fun () -> data <- f data)
67+
|> ignore
5768

58-
let internal render() = data
69+
let internal render key =
70+
let exists, value = data.TryGetValue key
71+
if exists then value else Configuration.Default
5972

6073

6174
[<RequireQualifiedAccess>]
@@ -72,10 +85,6 @@ module PaketPaths =
7285
type PaketDependencyManager(outputDirectory: string option, useResultsCache: bool) =
7386

7487
let resultCache = ConcurrentDictionary<string, ResolveDependenciesResult>()
75-
76-
let config = Configure.render()
77-
let log = config.Logger |> Option.defaultValue ignore
78-
7988

8089
member _.Name = "paket"
8190
member _.Key = "paket"
@@ -96,10 +105,20 @@ type PaketDependencyManager(outputDirectory: string option, useResultsCache: boo
96105
timeout: int
97106
) : obj =
98107

108+
let config = Configure.render scriptName
109+
let log = config.Logger |> Option.defaultValue ignore
110+
111+
if config.IsDefault then
112+
log "Using default config"
113+
else
114+
log "Using config override"
99115

100116
Logging.verbose <- config.Verbose
101117
Logging.verboseWarnings <- config.Verbose
102-
use _ = Paket.Logging.event.Publish |> Observable.subscribe (fun (e: Logging.Trace) -> log e.Text)
118+
119+
use _ =
120+
Paket.Logging.event.Publish
121+
|> Observable.subscribe (fun (e: Logging.Trace) -> log e.Text)
103122

104123
let getCacheKey (packageManagerTextLines: (string * string) seq) (tfm: string) (rid: string) =
105124
let content =
@@ -117,18 +136,19 @@ type PaketDependencyManager(outputDirectory: string option, useResultsCache: boo
117136
let hashes = Hash.fileHash scriptName None
118137
hashes.HashedScriptDir config.OutputRootDir)
119138

120-
let resultCacheDir = Path.Combine(workDir, "resolve-cache");
121-
139+
let resultCacheDir = Path.Combine(workDir, "resolve-cache")
140+
122141
Directory.CreateDirectory resultCacheDir |> ignore
123142

124143
Directory.EnumerateFiles resultCacheDir
125-
|> Seq.map (fun f -> Path.GetFileNameWithoutExtension f, File.ReadAllText f)
126-
|> Seq.iter (fun (key, content) ->
127-
let entry = JsonSerializer.Deserialize<ResolveDependenciesResult> content
128-
match entry with
129-
| null -> ()
130-
| validEntry -> resultCache.TryAdd(key, validEntry) |> ignore)
131-
144+
|> Seq.map (fun f -> Path.GetFileNameWithoutExtension f, File.ReadAllText f)
145+
|> Seq.iter (fun (key, content) ->
146+
let entry = JsonSerializer.Deserialize<ResolveDependenciesResult> content
147+
148+
match entry with
149+
| null -> ()
150+
| validEntry -> resultCache.TryAdd(key, validEntry) |> ignore)
151+
132152
let mutable isCached = true
133153
let cacheKey = getCacheKey packageManagerTextLines tfm runtimeIdentifier
134154

src/Queil.FSharp.DependencyManager.Paket/Queil.FSharp.DependencyManager.Paket.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
2020
<PackageReference Include="Paket.Core" Version="[9.0.2]" />
21-
<PackageReference Update="FSharp.Core" Version="[9.0.300]" />
21+
<PackageReference Update="FSharp.Core" Version="[9.0.303]" />
2222
</ItemGroup>
2323

2424
<ItemGroup>

src/Queil.FSharp.FscHost/FscHost.fs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,6 @@ module CompilerHost =
236236
open Queil.FSharp.DependencyManager.Paket
237237

238238
let getAssembly (options: Options) (script: Script) : Async<CompileOutput> =
239-
Configure.update (fun c ->
240-
{ c with
241-
OutputRootDir = options.OutputDir
242-
Verbose = options.Verbose
243-
Logger = options.Logger })
244239

245240
let log = options.Logger |> Option.defaultValue ignore
246241

@@ -251,8 +246,11 @@ module CompilerHost =
251246
log $"Script dir: %s{ctx.Dir}"
252247
log $"Cache dir: %s{ctx.OutputVersionDir}"
253248

254-
Configure.update (fun c ->
249+
Configure.update ctx.FilePath (fun c ->
255250
{ c with
251+
OutputRootDir = options.OutputDir
252+
Verbose = options.Verbose
253+
Logger = options.Logger
256254
ScriptOutputRootDir = Some ctx.OutputRootDir
257255
ScriptOutputVersionDir = Some ctx.OutputVersionDir })
258256

src/Queil.FSharp.FscHost/Queil.FSharp.FscHost.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
3232
<PackageReference Include="FSharp.Compiler.Service" Version="[43.9.300]" />
33-
<PackageReference Update="FSharp.Core" Version="[9.0.300]" />
33+
<PackageReference Update="FSharp.Core" Version="[9.0.303]" />
3434
</ItemGroup>
3535

3636
<ItemGroup>

src/Queil.FSharp.FscHost/packages.lock.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -976,9 +976,9 @@
976976
},
977977
"FSharp.Core": {
978978
"type": "Direct",
979-
"requested": "[9.0.300, 9.0.300]",
980-
"resolved": "9.0.300",
981-
"contentHash": "TVt2J7RCE1KCS2IaONF+p8/KIZ1eHNbW+7qmKF6hGoD4tXl+o07ja1mPtFjMqRa5uHMFaTrGTPn/m945WnDLiQ=="
979+
"requested": "[9.0.303, 9.0.303]",
980+
"resolved": "9.0.303",
981+
"contentHash": "6JlV8aD8qQvcmfoe/PMOxCHXc0uX4lR23u0fAyQtnVQxYULLoTZgwgZHSnRcuUHOvS3wULFWcwdnP1iwslH60g=="
982982
},
983983
"Chessie": {
984984
"type": "Transitive",
@@ -1901,15 +1901,15 @@
19011901
"queil.fsharp.dependencymanager.paket": {
19021902
"type": "Project",
19031903
"dependencies": {
1904-
"FSharp.Core": "[9.0.300, 9.0.300]",
1904+
"FSharp.Core": "[9.0.303, 9.0.303]",
19051905
"Paket.Core": "[9.0.2, 9.0.2]",
19061906
"Queil.FSharp.Hashing": "[1.0.0, )"
19071907
}
19081908
},
19091909
"queil.fsharp.hashing": {
19101910
"type": "Project",
19111911
"dependencies": {
1912-
"FSharp.Core": "[9.0.300, 9.0.300]"
1912+
"FSharp.Core": "[9.0.303, 9.0.303]"
19131913
}
19141914
}
19151915
}

src/Queil.FSharp.Hashing/Queil.FSharp.Hashing.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</ItemGroup>
2525

2626
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
27-
<PackageReference Update="FSharp.Core" Version="[9.0.300]" />
27+
<PackageReference Update="FSharp.Core" Version="[9.0.303]" />
2828
</ItemGroup>
2929

3030
</Project>

tests/unit/Main.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ open Expecto
44

55
[<EntryPoint>]
66
let main argv =
7-
Tests.runTestsInAssemblyWithCLIArgs [ No_Spinner; Sequenced ] argv
7+
Tests.runTestsInAssemblyWithCLIArgs [ No_Spinner ] argv

tests/unit/Paket.Tests.fs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ let paketTests =
99

1010
let options = Common.options
1111

12-
testSequencedGroup "Paket"
13-
<| testList
12+
testList
1413
"Paket"
1514
[
1615

@@ -68,7 +67,7 @@ let paketTests =
6867
let dir = "/tmp/.fsch/fixed-location"
6968

7069
let scriptFilePath = $"{dir}/paket.nuget.cache.fsx"
71-
Directory.CreateDirectory(dir) |> ignore
70+
Directory.CreateDirectory dir |> ignore
7271
File.WriteAllText(scriptFilePath, script)
7372

7473
let! resultFunc =
@@ -85,16 +84,16 @@ let paketTests =
8584
testAsync "Should support Paket GitHub" {
8685
let script =
8786
"""
88-
#r "paket: github queil/yzl src/Yzl/Yzl.fs"
89-
#load "queil/yzl/src/Yzl/Yzl.fs"
90-
namespace Script
87+
#r "paket: github queil/yzl src/Yzl/Yzl.fs"
88+
#load "queil/yzl/src/Yzl/Yzl.fs"
89+
namespace Script
9190
92-
module X =
91+
module X =
9392
94-
open Yzl
93+
open Yzl
9594
96-
let x () = 10 |> Yzl.render |> printfn "%s"
97-
"""
95+
let x () = 10 |> Yzl.render |> printfn "%s"
96+
"""
9897

9998
let! resultFunc =
10099
Common.invoke
@@ -105,4 +104,6 @@ let paketTests =
105104
(Member<unit -> unit>.Path "Script.X.x")
106105

107106
resultFunc ()
108-
} ]
107+
}
108+
109+
]

tests/unit/Queil.FSharp.FscHost.Tests.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<PackageReference Include="AltCover" Version="9.*" />
2222
<PackageReference Include="Expecto" Version="10.*" />
2323
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" />
24-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
25-
<PackageReference Update="FSharp.Core" Version="9.0.300" />
24+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.*" />
25+
<PackageReference Update="FSharp.Core" Version="9.0.303" />
2626
</ItemGroup>
2727

2828
<ItemGroup>

0 commit comments

Comments
 (0)