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/11/23 08:41:17 UTC

[GitHub] [pulsar] BewareMyPower commented on a change in pull request #12343: fix lastCumulativeAck.messageId npe when PersistentAcknowledgmentsGroupingTracker.flushSync

BewareMyPower commented on a change in pull request #12343:
URL: https://github.com/apache/pulsar/pull/12343#discussion_r754896282



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/PersistentAcknowledgmentsGroupingTracker.java
##########
@@ -477,13 +477,16 @@ public void flush() {
     private void flushAsync(ClientCnx cnx) {
         boolean shouldFlush = false;
         if (cumulativeAckFlushRequired) {
-            newMessageAckCommandAndWrite(cnx, consumer.consumerId, lastCumulativeAck.messageId.ledgerId,
-                    lastCumulativeAck.messageId.getEntryId(), lastCumulativeAck.bitSetRecyclable,
-                    AckType.Cumulative, null, Collections.emptyMap(), false,
-                    this.currentCumulativeAckFuture, null);
-            this.consumer.unAckedChunkedMessageIdSequenceMap.remove(lastCumulativeAck.messageId);
-            shouldFlush = true;
-            cumulativeAckFlushRequired = false;
+            final MessageIdImpl messageIdOfLastAck = lastCumulativeAck.messageId;

Review comment:
       @lhotari As I've explained in my PR, I think there is a possible thread safety problem like
   
   ```java
    if (lastCumulativeAck.messageId == null) { // 1. messageId is not null
        return false; 
    } 
    // 2. messageId was modified to null in another thread
    if (messageId.compareTo(lastCumulativeAck.messageId) <= 0) { // 3. messageId is null now
   ```
   
   
   I think the root cause is the design of `LastCumulativeAck` class. It's not well encapsulated. Though its fields are all private, the class is an inner class so the outer class can access the members directly. And we can see the direct access in many places, which makes it hard to analyze whether all the accesses are thread safe.




-- 
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: commits-unsubscribe@pulsar.apache.org

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