Skip to content
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

[C++] Fix segfault when get topic name from received message id #10006

Merged
merged 2 commits into from
Mar 22, 2021

Conversation

BewareMyPower
Copy link
Contributor

Motivation

Currently C++ client support get topic name from both received message and its message id. However, for a consumer that subscribes a non-partitioned topic, getting topic name from received message id will cause segmentation fault.

The C++ implementation of Message::getTopicName or MessageId::getTopicName requires the invocation of Message::setTopicName, which make the internal std::string* point to the topic string of the consumer. If setTopicName was not called, the getTopicName method would cause segmentation fault since a null pointer would be dereferenced.

However, when the consumer creates single messages from the batched message, setTopicName was not called.

Modifications

  • Use setTopicName for each single message when a consumer receives a batch.
  • Add related tests for all types of Consumer, including ConsumerImpl, MultiTopicsConsumerImpl and PartitionedConsumerImpl.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests ConsumerTest.testGetTopicNameFromReceivedMessage.

@BewareMyPower
Copy link
Contributor Author

/pulsarbot run-failure-checks

@merlimat merlimat merged commit 74c694f into apache:master Mar 22, 2021
@merlimat merlimat added the type/bug The PR fixed a bug or issue reported a bug label Mar 22, 2021
@codelipenghui codelipenghui added the cherry-picked/branch-2.7 Archived: 2.7 is end of life label Mar 24, 2021
codelipenghui pushed a commit that referenced this pull request Mar 24, 2021
* Fix segfault when get topic name from received message id

* Add tests for non-batched message

(cherry picked from commit 74c694f)
@BewareMyPower BewareMyPower deleted the bewaremypower/msg-id-topic-name branch April 23, 2021 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.7 Archived: 2.7 is end of life release/2.7.2 type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants