[Broker] Fix possible data race in getFirstAvailableConsumerPermits
* 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
@@ -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;
