Skip to content

Commit 072fd54

Browse files
committed
race condition: unsafe double check locking
tables.Add is called from within a lock, so presumably this code has been written to attemp to be thread safe, thus tables.TryGetValue must also be protected by lock
1 parent 8e3e42b commit 072fd54

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/fsharp/FSharp.Core/reflect.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,10 @@ module internal Impl =
404404
| _ -> invalidArg "tys" (SR.GetString(SR.invalidTupleTypes))
405405

406406
let tables = if isStruct then valueTupleTypes else refTupleTypes
407-
match tables.TryGetValue(asm) with
407+
match lock dictionaryLock (fun () -> tables.TryGetValue(asm)) with
408408
| false, _ ->
409+
// the Dictionary<>s here could be ConcurrentDictionary<>'s, but then
410+
// that would lock while initializing the Type array (maybe not an issue)
409411
let a = ref (Array.init<Type> 8 (fun i -> makeIt (i + 1)))
410412
lock dictionaryLock (fun () -> match tables.TryGetValue(asm) with
411413
| true, t -> a := t

0 commit comments

Comments
 (0)