315157973 commented on a change in pull request #8207:
URL: https://github.com/apache/pulsar/pull/8207#discussion_r500909339



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBase.java
##########
@@ -677,19 +677,16 @@ protected void notifyPendingBatchReceivedCallBack() {
         if (opBatchReceive == null || opBatchReceive.future == null) {
             return;
         }
-        notifyPendingBatchReceivedCallBack(opBatchReceive);
+        synchronized (incomingMessages) {

Review comment:
       > can you please explain the reason for this 'synchronized' block ?
   
   The `notifyPendingBatchReceivedCallBack(OpBatchReceive<T> opBatchReceive)` 
called in `notifyPendingBatchReceivedCallBack()` is not thread-safe, so locking 
is necessary.
   
   But not every call to `notifyPendingBatchReceivedCallBack()` needs to be 
locked, only when there is an opBatchReceive that meets the conditions.
   
   The scenarios where thread is not safe are as follows:
   Thread A calls incomingMessages.peek(), finds that message A meets the 
conditions, can join the Messages collection, and is preparing to poll. At this 
time, thread B polls the message A first. The message polled by thread A is 
actually message B, but message B does not meet the conditions for joining the 
Messages set of thread A.
   
   Look forward to your advice.




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


Reply via email to