You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/06/05 02:12:46 UTC

[GitHub] [pulsar] codelipenghui commented on a change in pull request #10831: [Broker] Fix possible data race in getFirstAvailableConsumerPermits

codelipenghui commented on a change in pull request #10831:
URL: https://github.com/apache/pulsar/pull/10831#discussion_r645926724



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
##########
@@ -673,7 +673,10 @@ protected int getFirstAvailableConsumerPermits() {
         }
         for (Consumer consumer : consumerList) {
             if (isConsumerAvailable(consumer)) {
-                return consumer.getAvailablePermits();
+                int availablePermits = consumer.getAvailablePermits();
+                if (availablePermits > 0) {
+                    return availablePermits;
+                }
             }

Review comment:
       Is better to change to:
   
   ```
   if (consumer != null && !consumer.isBlocked()) {
          return consumer.getAvailablePermits();
   }
   ```
   
   So that we don't need to check `availablePermits` twice




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org