EsotericSoftware / kryonet

TCP/UDP client/server library for Java, based on Kryo
BSD 3-Clause "New" or "Revised" License
1.81k stars 415 forks source link

ConcurrentModificationException in Client.java update #153

Closed MrStahlfelge closed 3 years ago

MrStahlfelge commented 5 years ago

Thanks for this great library.

I have this crash report sometimes in my crash logs:

java.util.ConcurrentModificationException: 
  at java.util.HashMap$HashIterator.nextNode (HashMap.java:1441)
  at java.util.HashMap$KeyIterator.next (HashMap.java:1465)
  at com.esotericsoftware.kryonet.Client.update (Client.java:148)
  at com.esotericsoftware.kryonet.Client.run (Client.java:20)
  at java.lang.Thread.run (Thread.java:784)

I don't know when it happens, as I didn't faced it myself. But it happens often enough, and on a lot of different devices, so it is definitely no one-time problem.

payne911 commented 4 years ago

Hey there @MrStahlfelge !

I had the same problem and realized the Socket IO Thread was modifying a variable which wasn't thread-safe and which was being called in libGDX's render() method (i.e. my UI Thread).

I changed the data structure used for that variable to something thread-safe and it stopped throwing that Exception. For example:

public List<Float> pingData = Collections.synchronizedList(new ArrayList<>());