Archomeda/Gw2Sharp

Race condition in MemoryCacheMethod

Archomeda opened this issue · 0 comments

I overlooked the possible race condition in the garbage collector in MemoryCacheMethod that might happen if it wants to delete at least 2 of the same keys from the ConcurrentDictionary at the same time. While .TryRemove(...) is thread-safe, the code around it is not. Meaning that if the key is already deleted, the other thread will fall in an infinite loop because it fails to delete it (because it doesn't exist anymore).