Jason918 commented on a change in pull request #14641:
URL: https://github.com/apache/pulsar/pull/14641#discussion_r834899169



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractDispatcherMultipleConsumers.java
##########
@@ -36,7 +37,7 @@
 
     protected final CopyOnWriteArrayList<Consumer> consumerList = new 
CopyOnWriteArrayList<>();
     protected final ObjectSet<Consumer> consumerSet = new ObjectHashSet<>();
-    protected volatile int currentConsumerRoundRobinIndex = 0;
+    protected volatile AtomicInteger currentConsumerRoundRobinIndex = new 
AtomicInteger(0);

Review comment:
       ```suggestion
       protected AtomicInteger currentConsumerRoundRobinIndex = new 
AtomicInteger(0);
   ```

##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractDispatcherMultipleConsumers.java
##########
@@ -119,26 +120,30 @@ public Consumer getNextConsumer() {
             return null;
         }
 
-        if (currentConsumerRoundRobinIndex >= consumerList.size()) {
-            currentConsumerRoundRobinIndex = 0;
+        // other thread will change consumerList
+        if (currentConsumerRoundRobinIndex.get() >= consumerList.size()) {
+            currentConsumerRoundRobinIndex.set(0);
         }
 
-        int currentRoundRobinConsumerPriority = 
consumerList.get(currentConsumerRoundRobinIndex).getPriorityLevel();
+        int currentRoundRobinConsumerPriority = 
consumerList.get(currentConsumerRoundRobinIndex.get())

Review comment:
       Still, there is race condition between Line 124 and Line 128, if 
`consumerList.size` decreases.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to