You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Race conditions with EnumExtensions has a race condition causing the thread safe IDictionary.Add method to throw an error.
If 2 threads both access Enum.ToStringOrDefaultValue() for the same value, both will pass the "is not present check" and both will then attempt to add the value. This causes a "The key already existed in the dictionary." exception.
I can't do a commit to this repo so I have attached a potential fix / refactor of enum extensions.
fail: The key already existed in the dictionary.
System.ArgumentException: The key already existed in the dictionary.
at System.Collections.Concurrent.ConcurrentDictionary`2.System.Collections.Generic.IDictionary<TKey,TValue>.Add(TKey key, TValue value)
at BricklinkSharp.Client.Extensions.EnumExtensions.GetStringValueOrDefault(Enum e)
at BricklinkSharp.Client.BricklinkClient.GetItemAsync(ItemType type, String no, CancellationToken cancellationToken)
Thanks for your contribution 👍.
Your solution is (besides the bug fix) also more efficient since we can get rid of the reflection.
I think the Obsolete Flag is not required since the extensions are internal anyway and you can remove the GetStringValueOrDefault methods. Also the StringValueAttribute is not needed anymore.
You can only commit to this repo via pull requests (PRs). Therefore you have to fork the repo into your personal space and commit into that repo. From there you can create PRs.
Thanks again for the PR.
I'll release a new version, but not quite sure whether this should be a 2.0.0 since the namespace for Enums changed (which needs to be adjusted) and I also found a typo in RatingTargeRole.
What do you think?
Race conditions with EnumExtensions has a race condition causing the thread safe IDictionary.Add method to throw an error.
If 2 threads both access Enum.ToStringOrDefaultValue() for the same value, both will pass the "is not present check" and both will then attempt to add the value. This causes a "The key already existed in the dictionary." exception.
I can't do a commit to this repo so I have attached a potential fix / refactor of enum extensions.
fail: The key already existed in the dictionary.
System.ArgumentException: The key already existed in the dictionary.
at System.Collections.Concurrent.ConcurrentDictionary`2.System.Collections.Generic.IDictionary<TKey,TValue>.Add(TKey key, TValue value)
at BricklinkSharp.Client.Extensions.EnumExtensions.GetStringValueOrDefault(Enum e)
at BricklinkSharp.Client.BricklinkClient.GetItemAsync(ItemType type, String no, CancellationToken cancellationToken)
BricklinkSharp.zip
The text was updated successfully, but these errors were encountered: