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 2022/05/28 02:35:52 UTC

[GitHub] [pulsar] Technoboy- opened a new pull request, #15820: [fix][broker] Fix NPE in MessageDeduplication.

Technoboy- opened a new pull request, #15820:
URL: https://github.com/apache/pulsar/pull/15820

   ### Motivation
   
   When MessageDeduplication#purgeInactiveProducers:
   https://github.com/apache/pulsar/blob/d09c6eb26adcaf0aff2c3464e445eb8df5af70a6/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/MessageDeduplication.java#L455-L477
   
   If MessageDeduplication status is not `Enabled`, the cursor will be null. and cause to be NPE at line 475.
   
   
   ### StackTrace
   ```
   May 25, 2022 @ 13:39:04.552	2022-05-25T05:39:04,546+0000 [pulsar-inactivity-monitor-22-1] ERROR org.apache.bookkeeper.common.util.SafeRunnable - Unexpected throwable caught 
   May 25, 2022 @ 13:39:04.552		at org.apache.pulsar.broker.service.BrokerService.lambda$forEachTopic$78(BrokerService.java:1768) 
   May 25, 2022 @ 13:39:04.552		at org.apache.pulsar.broker.service.persistent.MessageDeduplication.purgeInactiveProducers(MessageDeduplication.java:475) 
   May 25, 2022 @ 13:39:04.552		at java.util.Optional.ifPresent(Optional.java:183) ~[?:?]
   May 25, 2022 @ 13:39:04.552		at org.apache.pulsar.broker.service.BrokerService.checkMessageDeduplicationInfo(BrokerService.java:1735) 
   May 25, 2022 @ 13:39:04.552		at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
   May 25, 2022 @ 13:39:04.552		at org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap.forEach(ConcurrentOpenHashMap.java:272) 
   May 25, 2022 @ 13:39:04.552		at org.apache.bookkeeper.common.util.SafeRunnable.run(SafeRunnable.java:36) 
   May 25, 2022 @ 13:39:04.552	java.lang.NullPointerException: null
   May 25, 2022 @ 13:39:04.552		at org.apache.pulsar.broker.service.BrokerService.forEachTopic(BrokerService.java:1766) 
   May 25, 2022 @ 13:39:04.552		at org.apache.bookkeeper.mledger.util.SafeRun$1.safeRun(SafeRun.java:32) 
   ```
   
   ### Documentation
   
   - [x] `doc-not-needed` 
   (Please explain why)
     


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


[GitHub] [pulsar] Technoboy- merged pull request #15820: [fix][broker] Fix NPE in MessageDeduplication.

Posted by GitBox <gi...@apache.org>.
Technoboy- merged PR #15820:
URL: https://github.com/apache/pulsar/pull/15820


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


[GitHub] [pulsar] Technoboy- commented on pull request #15820: [fix][broker] Fix NPE in MessageDeduplication.

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on PR #15820:
URL: https://github.com/apache/pulsar/pull/15820#issuecomment-1140578020

   > I'm not sure if it could solve the NPE. Is there a race condition like the following code snippet I commented?
   > 
   > ```java
   >         if (hasInactive && isEnabled()) { // 1. isEnabled() returns true, managedCursor is not null
   >             // during 1 and 2, some other methods changed `managedCursor` to null
   >             takeSnapshot(getManagedCursor().getMarkDeletedPosition()); // 2. managedCursor might be null
   > ```
   > 
   > I'd prefer the following way.
   > 
   > ```java
   >         final ManagedCursor cursor = managedCursor;
   >         if (hasInactive && cursor != null) {
   >             takeSnapshot(cursor.getMarkDeletedPosition(), cursor);
   >         }
   > ```
   > 
   > ```java
   >     private void takeSnapshot(Position position) {
   >         takeSnapshot(position, getManagedCursor());
   >     }
   > 
   >     private void takeSnapshot(Position position, ManagedCursor cursor) {
   >         /* ... */
   >         cursor.asyncMarkDelete(position, snapshot, new MarkDeleteCallback() {
   > ```
   
   yes, this could avoid the case when there is race condition.


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


[GitHub] [pulsar] Technoboy- commented on pull request #15820: [fix][broker] Fix NPE in MessageDeduplication.

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on PR #15820:
URL: https://github.com/apache/pulsar/pull/15820#issuecomment-1140580986

   > I'm not sure if it could solve the NPE. Is there a race condition like the following code snippet I commented?
   > 
   > ```java
   >         if (hasInactive && isEnabled()) { // 1. isEnabled() returns true, managedCursor is not null
   >             // during 1 and 2, some other methods changed `managedCursor` to null
   >             takeSnapshot(getManagedCursor().getMarkDeletedPosition()); // 2. managedCursor might be null
   > ```
   > 
   > I'd prefer the following way.
   > 
   > ```java
   >         final ManagedCursor cursor = managedCursor;
   >         if (hasInactive && cursor != null) {
   >             takeSnapshot(cursor.getMarkDeletedPosition(), cursor);
   >         }
   > ```
   > 
   > ```java
   >     private void takeSnapshot(Position position) {
   >         takeSnapshot(position, getManagedCursor());
   >     }
   > 
   >     private void takeSnapshot(Position position, ManagedCursor cursor) {
   >         /* ... */
   >         cursor.asyncMarkDelete(position, snapshot, new MarkDeleteCallback() {
   > ```
   
   Method `checkStatus` and `purgeInactiveProducers` is `synchonized`.  Seems no race condition.


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


[GitHub] [pulsar] github-actions[bot] commented on pull request #15820: [fix][broker] Fix NPE in MessageDeduplication.

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #15820:
URL: https://github.com/apache/pulsar/pull/15820#issuecomment-1140147127

   @Technoboy-:Thanks for your contribution. For this PR, do we need to update docs?
   (The [PR template contains info about doc](https://github.com/apache/pulsar/blob/master/.github/PULL_REQUEST_TEMPLATE.md#documentation), which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)


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