You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2020/07/24 17:08:46 UTC

[pulsar] branch master updated: [C++] Fix multitopic consumer segfault on connect error (#7588)

This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 09caa92  [C++] Fix multitopic consumer segfault on connect error (#7588)
09caa92 is described below

commit 09caa92565f2a0eb862becabde6ff2028fc47da1
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Fri Jul 24 10:08:24 2020 -0700

    [C++] Fix multitopic consumer segfault on connect error (#7588)
---
 pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc | 13 ++++++++-----
 pulsar-client-cpp/tests/BasicEndToEndTest.cc     | 13 +++++++++++++
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc b/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc
index b9b4635..85a9868 100644
--- a/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc
+++ b/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc
@@ -104,8 +104,7 @@ void MultiTopicsConsumerImpl::handleOneTopicSubscribed(Result result, Consumer c
         } else {
             LOG_ERROR("Unable to create Consumer - " << consumerStr_ << " Error - " << result);
             // unsubscribed all of the successfully subscribed partitioned consumers
-            ResultCallback nullCallbackForCleanup = NULL;
-            closeAsync(nullCallbackForCleanup);
+            closeAsync(nullptr);
             multiTopicsConsumerCreatedPromise_.setFailed(result);
             return;
         }
@@ -372,17 +371,21 @@ void MultiTopicsConsumerImpl::closeAsync(ResultCallback callback) {
     if (state_ == Closing || state_ == Closed) {
         LOG_ERROR("TopicsConsumer already closed "
                   << " topic" << topic_ << " consumer - " << consumerStr_);
-        callback(ResultAlreadyClosed);
+        if (callback) {
+            callback(ResultAlreadyClosed);
+        }
         return;
     }
 
     setState(Closing);
 
     if (consumers_.empty()) {
-        LOG_ERROR("TopicsConsumer have no consumers to close "
+        LOG_DEBUG("TopicsConsumer have no consumers to close "
                   << " topic" << topic_ << " subscription - " << subscriptionName_);
         setState(Closed);
-        callback(ResultAlreadyClosed);
+        if (callback) {
+            callback(ResultAlreadyClosed);
+        }
         return;
     }
 
diff --git a/pulsar-client-cpp/tests/BasicEndToEndTest.cc b/pulsar-client-cpp/tests/BasicEndToEndTest.cc
index 5bc8f78..b574630 100644
--- a/pulsar-client-cpp/tests/BasicEndToEndTest.cc
+++ b/pulsar-client-cpp/tests/BasicEndToEndTest.cc
@@ -1822,6 +1822,19 @@ TEST(BasicEndToEndTest, testMultiTopicsConsumerTopicNameInvalid) {
     client.shutdown();
 }
 
+TEST(BasicEndToEndTest, testMultiTopicsConsumerConnectError) {
+    Client client("pulsar://invalid-hostname:6650");
+    std::vector<std::string> topicNames;
+    topicNames.push_back("topic-1");
+    topicNames.push_back("topic-2");
+
+    Consumer consumer;
+    Result res = client.subscribe(topicNames, "sub", consumer);
+    ASSERT_EQ(ResultConnectError, res);
+
+    client.shutdown();
+}
+
 TEST(BasicEndToEndTest, testMultiTopicsConsumerDifferentNamespace) {
     Client client(lookupUrl);
     std::vector<std::string> topicNames;