Azure / DotNetty

DotNetty project – a port of netty, event-driven asynchronous network application framework
Other
4.09k stars 977 forks source link

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

Open dnickless opened 4 years ago

dnickless commented 4 years ago

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()
491134648 commented 4 years ago

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