Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cory-hrh opened this issue Jul 26, 2022 · 0 comments
Open

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

cory-hrh opened this issue Jul 26, 2022 · 0 comments

Comments

@cory-hrh
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant