gaozhangmin opened a new pull request #14656:
URL: https://github.com/apache/pulsar/pull/14656
### Motivation
NPE when trying removeSubscription.
```
Caused by: java.lang.NullPointerException
at
org.apache.pulsar.broker.service.persistent.PersistentTopic.removeSubscription(PersistentTopic.java:1054)
~[org.apache.pulsar-pulsar-broker-2.10.0.jar:2.10.0]
at
org.apache.pulsar.broker.service.persistent.PersistentTopic$5.deleteCursorComplete(PersistentTopic.java:1030)
~[org.apache.pulsar-pulsar-broker-2.10.0.jar:2.10.0]
at
org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.asyncDeleteCursor(ManagedLedgerImpl.java:970)
~[org.apache.pulsar-managed-ledger-2.10.0.jar:2.10.0]
at
org.apache.pulsar.broker.service.persistent.PersistentTopic.asyncDeleteCursor(PersistentTopic.java:1024)
~[org.apache.pulsar-pulsar-broker-2.10.0.jar:2.10.0]
at
org.apache.pulsar.broker.service.persistent.PersistentTopic.unsubscribe(PersistentTopic.java:1017)
~[org.apache.pulsar-pulsar-broker-2.10.0.jar:2.10.0]
at
org.apache.pulsar.broker.service.persistent.PersistentSubscription.lambda$delete$19(PersistentSubscription.java:852)
~[org.apache.pulsar-pulsar-broker-2.10.0.jar:2.10.0]
```
This cause by when trying `doUnsubscribe`, if a cursor is nondurable, both
`consumer.close()` and `delete()` will try to invoke `removeSubscription`.
this will cause NPE.
```
@Override
public CompletableFuture<Void> doUnsubscribe(Consumer consumer) {
CompletableFuture<Void> future = new CompletableFuture<>();
try {
if (dispatcher.canUnsubscribe(consumer)) {
consumer.close();
return delete();
}
future.completeExceptionally(
new ServerMetadataException("Unconnected or shared
consumer attempting to unsubscribe"));
} catch (BrokerServiceException e) {
log.warn("Error removing consumer {}", consumer);
future.completeExceptionally(e);
}
return future;
}
```
### Modifications
remove `removeSubscription` in method `consumer.close()` if cursor is
nondurable.
### Documentation
Check the box below or label this PR directly (if you have committer
privilege).
Need to update docs?
- [ ] `doc-required`
(If you need help on updating docs, create a doc issue)
- [ ] `no-need-doc`
(Please explain why)
- [ ] `doc`
(If this PR contains doc changes)
--
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]