eolivelli commented on code in PR #16812:
URL: https://github.com/apache/pulsar/pull/16812#discussion_r930848103


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java:
##########
@@ -528,26 +533,38 @@ public synchronized void readEntriesComplete(List<Entry> 
entries, Object ctx) {
             log.debug("[{}] Distributing {} messages to {} consumers", name, 
entries.size(), consumerList.size());
         }
 
+        // dispatch messages to a separate thread, but still in order for this 
subscription
+        // sendMessagesToConsumers is responsible for running broker-side 
filters
+        // that may be quite expensive
         if (serviceConfig.isDispatcherDispatchMessagesInSubscriptionThread()) {
-            // dispatch messages to a separate thread, but still in order for 
this subscription
-            // sendMessagesToConsumers is responsible for running broker-side 
filters
-            // that may be quite expensive
+            // setting sendInProgress here, because sendMessagesToConsumers 
will be executed
+            // in a separate thread, and we want to prevent more reads
+            sendInProgress = true;
             dispatchMessagesThread.execute(safeRun(() -> 
sendMessagesToConsumers(readType, entries)));
         } else {
             sendMessagesToConsumers(readType, entries);
         }
     }
 
     protected synchronized void sendMessagesToConsumers(ReadType readType, 
List<Entry> entries) {
+        sendInProgress = true;
+        try {
+            trySendMessagesToConsumers(readType, entries);
+        } finally {
+            sendInProgress = false;
+        }
+        readMoreEntries();
+    }
 
+    protected synchronized void trySendMessagesToConsumers(ReadType readType, 
List<Entry> entries) {

Review Comment:
   you are right, thanks for the heads up
   I will also add a comment for future people who will put their hands here



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