vert-x3 / vertx-zookeeper

Zookeeper based cluster manager implementation
Other
72 stars 67 forks source link

SubsMapHelper has the possibility of ConcurrentModificationException #151

Open bigtrouble opened 2 months ago

bigtrouble commented 2 months ago

Questions

Found the following error message on my system.

java.util.ConcurrentModificationException: null
        at java.base/java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:1023)
        at java.base/java.util.LinkedHashMap$LinkedKeyIterator.next(LinkedHashMap.java:1046)
        at io.vertx.spi.cluster.zookeeper.impl.SubsMapHelper.lambda$childEvent$14(SubsMapHelper.java:187)
        at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:279)
        at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:261)
        at io.vertx.core.impl.ContextInternal.lambda$runOnContext$0(ContextInternal.java:59)
        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:1583)

Version

4.5.8

Extra

Collections.synchronizedSet is not synchronized in a useful way. Using CopyOnWriteArraySet might be a good way.

io.vertx.spi.cluster.zookeeper.impl.SubsMapHelper (line: 86)

  private Set<RegistrationInfo> addToSet(RegistrationInfo registrationInfo, Set<RegistrationInfo> curr) {
    Set<RegistrationInfo> res = curr != null ? curr : Collections.synchronizedSet(new LinkedHashSet<>());
    res.add(registrationInfo);
    return res;
  }

io.vertx.spi.cluster.zookeeper.impl.SubsMapHelper (line: 186)

   for (Map.Entry<String, Set<RegistrationInfo>> entry : ownSubs.entrySet()) {
      for (RegistrationInfo registrationInfo : entry.getValue()) {
         Promise<Void> promise = Promise.promise();
         put(entry.getKey(), registrationInfo, promise);
         futures.add(promise.future());
      }
   }
tsegismont commented 2 months ago

Would you like to share a pull request?