chaitu236 / TakServer

Server to handle online TAK games
https://www.playtak.com
GNU General Public License v2.0
35 stars 8 forks source link

Fix a ConcurrentModificationException #28

Closed nelhage closed 7 years ago

nelhage commented 7 years ago

I saw this in local testing:

Exception in thread "Thread-56" java.util.ConcurrentModificationException
        at java.util.HashMap$HashIterator.nextNode(HashMap.java:1437)
        at java.util.HashMap$KeyIterator.next(HashMap.java:1461)
        at tak.Seek$1.run(Seek.java:78)

The problem comes from the iteration over seekListeners; As documented, a synchronizedSet still must be explicitly synchronized for iteration.

Instead of synchronizing, make a copy before spawning the thread, so that mutations can occur on the canonical copy while the thread dispatches notifications in the background.

chaitu236 commented 7 years ago

Fixed in 4ca51a07d1702de9a4d9af17c5c14efd1326dc21 using ConcurrentHashSet instead.