You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2021/06/05 14:55:28 UTC

[pulsar] branch master updated: [Broker] Fix possible data race in getFirstAvailableConsumerPermits (#10831)

This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new bd568bc  [Broker] Fix possible data race in getFirstAvailableConsumerPermits (#10831)
bd568bc is described below

commit bd568bcb0cadc368d7c5b5aa09437b8d9a174733
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Sat Jun 5 17:54:16 2021 +0300

    [Broker] Fix possible data race in getFirstAvailableConsumerPermits (#10831)
    
    * Fix possible race in getFirstAvailableConsumerPermits
    
    - there's a chance for a race so that the consumer's available permits goes
      below zero after it has been checked in "isConsumerAvailable"
    
    * Address review feedback
---
 .../service/persistent/PersistentDispatcherMultipleConsumers.java  | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
index 6756c4a..3426355 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
@@ -672,8 +672,11 @@ public class PersistentDispatcherMultipleConsumers extends AbstractDispatcherMul
             return 0;
         }
         for (Consumer consumer : consumerList) {
-            if (isConsumerAvailable(consumer)) {
-                return consumer.getAvailablePermits();
+            if (consumer != null && !consumer.isBlocked()) {
+                int availablePermits = consumer.getAvailablePermits();
+                if (availablePermits > 0) {
+                    return availablePermits;
+                }
             }
         }
         return 0;