divijvaidya commented on PR #13285: URL: https://github.com/apache/kafka/pull/13285#issuecomment-1448210313
Hey @chia7712 > the mutable ArrayBuffer won't be modified after it is created I have a different view of this. Please correct me if I am wrong. The number of network threads is dynamically reconfigurable in a broker. `processors` in `SocketServer.scala` has one processor per thread. Hence, it is possible to add/remove entries from `ArrayBuffer[Processor]` while the server is already running. An example of this situation is in `SocketServer.scala#reconfigure()` (line 503) function where we call `addProcessors()` (or `removeProcessors()`) and eventually `processors ++= listenerProcessors`. Consider the following scenario which will go wrong with the changes in this PR: 1. Thread 1 (metric thread) tries to read from `processors` at line 119 of `SocketServer.scala` 2. At the same time, Thread 2 (network thread) invokes `override def reconfigure(configs: util.Map[String, _]): Unit` which calls `addProcessors()` which tried to acquire a lock on `this` and successfully obtains it (because we have removed the acquisition of lock from the metrics and hence Thread 1 is running without acquiring a lock). After obtaining the lock it adds a value to `ArrayBuffer[Processor]`. 3. We have both Thread 1 and Thread 2 attempting to read/write from `mutable ArrayBuffer`. This is not a thread safe collection and hence the result could lead to inconsistent state for ArrayBuffer. -- 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