-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Summary
If you are creating new EnumValue instances on multiple threads there is a possibility of collisions causing run-time failures.
This was observed when creating Energistics.DataAccess.WITSML141.QualifierType instances on multiple threads threw an InvalidOperationException as you cannot modify a collection when iterating over it.
Technical details
The issue is in the Register() method in Energistics.DataAccess.EnumValue. This accesses a static ConcurrentDictionary<Type, List<EnumValue>> instance.
The issue is that although the ConcurrentDictionary is thread-safe the List it returns is not.
The Register() method both iterates over this List and can add new elements to it.
Therefore you can have Thread A iterating over the list while Thread B simultaneously modifies it causing Thread A to throw an exception.