LiamClarkeNZ commented on a change in pull request #11920: URL: https://github.com/apache/kafka/pull/11920#discussion_r833080985
########## File path: core/src/main/scala/kafka/server/DynamicBrokerConfig.scala ########## @@ -201,7 +202,9 @@ class DynamicBrokerConfig(private val kafkaConfig: KafkaConfig) extends Logging private[server] val staticDefaultConfigs = ConfigDef.convertToStringMapWithPasswordValues(KafkaConfig.defaultValues.asJava).asScala private val dynamicBrokerConfigs = mutable.Map[String, String]() private val dynamicDefaultConfigs = mutable.Map[String, String]() - private val reconfigurables = mutable.Buffer[Reconfigurable]() + + // Use COWArrayList to prevent concurrent modification exception when reconfigurable added while iteration over list occurring + private val reconfigurables = new CopyOnWriteArrayList[Reconfigurable]() private val brokerReconfigurables = mutable.Buffer[BrokerReconfigurable]() Review comment: That's a good question. I am happy to do so, I don't have much experience in this area of code, I just wanted to help eliminate some flaky tests, but I can't see any downsides to doing so. I chose to use a `CopyOnWriteArrayList` because iteration over the reconfigurables is a lot more common than adding items, so the overhead is cheap. I also looked at a `ConcurrentQueue`, as that also avoids the concurrent modification exception, and is cheaper to add items to. I chose the COWArrayList because iteration over a ConcurrentQueue one is non-deterministic - i.e., a freshly added Reconfigurable could appear in an iteration that's currently occurring, and I'm not sure if that's safe or not. Whereas the CopyOnWriteArrayList offers deterministic iteration. So, if people are happy for me to extend the change to the brokerReconfigurables also defensively, I'd be pleased to do it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org