Concurrency issue in ping failed listeners set

Hello devs,

I believe there is a race condition when iterating over pingFailedListeners in PingManager:

java.util.ConcurrentModificationException at java.util.HashMap$HashIterator.nextEntry(HashMap.java:788) at java.util.HashMap$KeyIterator.next(HashMap.java:815) at org.jivesoftware.smackx.ping.PingManager.pingMyServer(PingManager.java:252) at org.kontalk.service.msgcenter.MessageCenterService$3.run(MessageCenterService.java:1114) at java.lang.Thread.run(Thread.java:818)

It鈥檚 a synchronized set and that鈥檚 ok, but access to it should be synchronized manually (source: Collections (Java Platform SE 7 ))

For reference: Smack concurrency issue for ping failed listener 路 Issue #955 路 kontalk/androidclient 路 GitHub

Best

Thanks, fixed with Use CopyOnWriteArraySet for pingFailedListeners 路 Flowdalic/Smack@6cfdf2b 路 GitHub

1 Like

Thank you for the quick fix. Any chance this might get into 4.1 as well? :slight_smile:

Sadly not, i鈥檝e have to stop supporting old version at some time. But nothing prevents you backporting the fix if you want to stay on 4.1. Just copy the PingManager code, fix it, and place it in a different package or rename the manager to e.g. PingManagerV2.

No problem, thank you. I鈥檒l do that until I鈥檒l switch to Smack 4.2.