Tags: NFig/NFig
Tags
Fix race condition in initialization of `SettingsFactory` In the ctor of `SettingsFactory` the call to `BuildSettings` enumerates the properties of the top-level type in parallel. That attempts to populate a cache containing delegates to generate `Setting` objects from `PropertyInfo` objects. However, that cache is a `Dictionary<TKey, TValue>` - any calls to `TryGetValue` are not thread-safe - the underlying buckets and entries are mutated as part of an insert or update operation on the dictionary. In this case the first call to `TryGetValue` was not protected by a lock around the critical section and so if another thread inserted a new entry the call to `TryGetValue` would occasionally fail with a `NullReferenceException` as the underlying buckets/entries were modified. This commit changes the dictionary to be a `ConcurrentDictionary` and removes the need for a lock entirely. As this is only used during initialization of the settings the impact is minimal.
PreviousNext