Skip to content

Energistics.DataAccess.EnumValue isn't thread-safe #7

@cory-hrh

Description

@cory-hrh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions