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

rxl pushed a commit to branch branch-2.6
in repository https://gitbox.apache.org/repos/asf/pulsar.git

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

    [C++] Fix multitopic consumer segfault on connect error (#7588)
    
    
    (cherry picked from commit 09caa92565f2a0eb862becabde6ff2028fc47da1)
---
 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 564aba2..cc71a35 100644
--- a/pulsar-client-cpp/tests/BasicEndToEndTest.cc
+++ b/pulsar-client-cpp/tests/BasicEndToEndTest.cc
@@ -1820,6 +1820,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;

Reply via email to