-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix][client] Fix NPE when acknowledging multiple messages #19874
[fix][client] Fix NPE when acknowledging multiple messages #19874
Conversation
### Motivation For a multi-topics consumer, when it acknowledges a single message, it will first find the owner topic from its message ID. If the owner topic is not subscribed by the consumer, `NotConnectedException` will be thrown. However, when it acknowledges multiple messages, if any of them is the message whose owner topic is not subscribed by the consumer, NPE will happen instead. ### Modifications When acknowledging multiple messages, ignore the message IDs whose owner topic is not subscribed. `testAckMessageInAnotherTopic` is added to cover this case. ### TODO There are many other places that do not check if `consumers.get` returns `null`, like `doReconsumeLater`, `negativeAcknowledge`, etc. This patch does not cover them.
@BewareMyPower Please add the following content to your PR description and select a checkbox:
|
I decide to ignore these invalid message IDs because in real world, it usually happens when these messages are not received by the consumer or the topic of them has been deleted and the consumer subscribes topic by a regex. |
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MultiTopicsConsumerImpl.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Motivation
For a multi-topics consumer, when it acknowledges a single message, it will first find the owner topic from its message ID. If the owner topic is not subscribed by the consumer,
NotConnectedException
will be thrown.However, when it acknowledges multiple messages, if any of them is the message whose owner topic is not subscribed by the consumer, NPE will happen instead.
Modifications
When acknowledging multiple messages, if there is any message ID whose owner topic is not subscribed, fail the whole acknowledgment.
testAckMessageInAnotherTopic
is added to cover this case.TODO
There are many other places that do not check if
consumers.get
returnsnull
, likedoReconsumeLater
,negativeAcknowledge
, etc. This patch does not cover them.Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: BewareMyPower#22