DotNetty icon indicating copy to clipboard operation
DotNetty copied to clipboard

Error when calling FastThreadLocal.RemoveAll(): Collection was modified

Open dnickless opened this issue 4 years ago • 1 comments

https://github.com/Azure/DotNetty/blob/47f5ec7303037f1360615d182939e04d8619a2b3/src/DotNetty.Common/FastThreadLocal.cs#L32

I think that comment is unpleasantly true, you will need to create a clone as you're removing items from the collection that you're iterating over...

This is what I'm seeing (it seems as this only occurs upon the second call):

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.HashSet`1.Enumerator.MoveNext()
   at DotNetty.Common.FastThreadLocal.RemoveAll()

dnickless avatar Nov 14 '19 15:11 dnickless

Other threads are modifying Collection, either with a for implementation or a new List reserved deleted object, and then call List remove to delete the implementation

491134648 avatar Nov 28 '19 17:11 491134648