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/05/14 07:45:26 UTC

[GitHub] [pulsar] BewareMyPower opened a new pull request #10586: Fix NPE when ACK grouping tracker checks duplicated message id

BewareMyPower opened a new pull request #10586:
URL: https://github.com/apache/pulsar/pull/10586


   ### Motivation
   
   Recently I encountered the following NPE but it's hard to reproduce.
   
   ```
   01:40:14.630 [pulsar-client-io-54-1] WARN  org.apache.pulsar.client.impl.ClientCnx - [10.0.0.44/10.0.0.44:6650] Got exception java.lang.NullPointerException
       at org.apache.pulsar.client.impl.MessageIdImpl.compareTo(MessageIdImpl.java:213)
       at org.apache.pulsar.client.impl.MessageIdImpl.compareTo(MessageIdImpl.java:37)
       at org.apache.pulsar.client.impl.PersistentAcknowledgmentsGroupingTracker.isDuplicate(PersistentAcknowledgmentsGroupingTracker.java:117)
       at org.apache.pulsar.client.impl.ConsumerImpl.messageReceived(ConsumerImpl.java:1013)
   ```
   
   From the stack we can see NPE was thrown when an ACK grouping tracker checks duplicated message id. The track maintains a `LastCumulativeAck` field that has a `MessageIdImpl` type field `messageId`. However, `messageId` could be null after `recycle()` or just was created with a null `MessageIdImpl`. We should check null here. Anyway, it may be introduced from https://github.com/apache/pulsar/pull/9440
   
   ### Modifications
   
   - Check null in `PersistentAcknowledgmentsGroupingTracker#isDuplicate` and returns false if it's null, then the tracker will do nothing in `ConsumerImpl#messageReceived`.
   - Check null in `MessageIdImpl#compareTo` and throw `UnsupportedOperationException` if the compared object is null.
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   This change is a trivial rework / code cleanup without any test coverage.


-- 
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:
users@infra.apache.org



[GitHub] [pulsar] eolivelli commented on a change in pull request #10586: Fix NPE when ACK grouping tracker checks duplicated message id

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #10586:
URL: https://github.com/apache/pulsar/pull/10586#discussion_r632365085



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java
##########
@@ -210,7 +210,8 @@ public int compareTo(MessageId o) {
         } else if (o instanceof TopicMessageIdImpl) {
             return compareTo(((TopicMessageIdImpl) o).getInnerMessageId());
         } else {
-            throw new UnsupportedOperationException("Unknown MessageId type: " + o.getClass().getName());
+            final String typeName = (o != null) ? o.getClass().getName() : "null";

Review comment:
       we can add a check in the beginning of the method.
   
   ```
   if (o == null) {
      throw new UnsupportedOperationException(....)
   }
   ```




-- 
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:
users@infra.apache.org



[GitHub] [pulsar] eolivelli commented on a change in pull request #10586: Fix NPE when ACK grouping tracker checks duplicated message id

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #10586:
URL: https://github.com/apache/pulsar/pull/10586#discussion_r632365085



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java
##########
@@ -210,7 +210,8 @@ public int compareTo(MessageId o) {
         } else if (o instanceof TopicMessageIdImpl) {
             return compareTo(((TopicMessageIdImpl) o).getInnerMessageId());
         } else {
-            throw new UnsupportedOperationException("Unknown MessageId type: " + o.getClass().getName());
+            final String typeName = (o != null) ? o.getClass().getName() : "null";

Review comment:
       what about adding a check in the beginning of the method ? the code will be easier to read. null checks are not expensive
   
   ```
   if (o == null) {
      throw new UnsupportedOperationException(....)
   }
   ```




-- 
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:
users@infra.apache.org



[GitHub] [pulsar] BewareMyPower commented on pull request #10586: Fix NPE when ACK grouping tracker checks duplicated message id

Posted by GitBox <gi...@apache.org>.
BewareMyPower commented on pull request #10586:
URL: https://github.com/apache/pulsar/pull/10586#issuecomment-841178616


   Now all tests passed, PTAL again @eolivelli 


-- 
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:
users@infra.apache.org



[GitHub] [pulsar] BewareMyPower commented on a change in pull request #10586: Fix NPE when ACK grouping tracker checks duplicated message id

Posted by GitBox <gi...@apache.org>.
BewareMyPower commented on a change in pull request #10586:
URL: https://github.com/apache/pulsar/pull/10586#discussion_r632372675



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java
##########
@@ -210,7 +210,8 @@ public int compareTo(MessageId o) {
         } else if (o instanceof TopicMessageIdImpl) {
             return compareTo(((TopicMessageIdImpl) o).getInnerMessageId());
         } else {
-            throw new UnsupportedOperationException("Unknown MessageId type: " + o.getClass().getName());
+            final String typeName = (o != null) ? o.getClass().getName() : "null";

Review comment:
       I agree.




-- 
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:
users@infra.apache.org



[GitHub] [pulsar] eolivelli merged pull request #10586: Fix NPE when ACK grouping tracker checks duplicated message id

Posted by GitBox <gi...@apache.org>.
eolivelli merged pull request #10586:
URL: https://github.com/apache/pulsar/pull/10586


   


-- 
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:
users@infra.apache.org