shibd commented on code in PR #16969:
URL: https://github.com/apache/pulsar/pull/16969#discussion_r951247886


##########
pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc:
##########
@@ -363,13 +401,12 @@ void MultiTopicsConsumerImpl::closeAsync(ResultCallback 
callback) {
 
     auto self = shared_from_this();
     int numConsumers = 0;
-    consumers_.forEach(
-        [&numConsumers, &self, callback](const std::string& name, const 
ConsumerImplPtr& consumer) {
-            numConsumers++;
-            consumer->closeAsync([self, name, callback](Result result) {
-                self->handleSingleConsumerClose(result, name, callback);
-            });
+    for (const auto& item : consumers_.toPairVector()) {

Review Comment:
   @BewareMyPower Sorry, maybe I didn't make it clear. The problem now is that 
we did a `remove` operation in the function of `forEachValue`.
   
   case this:
   ```c++
   class TestClass{
      public:
       std::string key;
       void print(){
           std::cout << "test ttt." << std::endl;
       };
   };
   
   TEST(SchemaTest, ttt) {
       SynchronizedHashMap<std::string, std::shared_ptr<TestClass>> map;
   
       std::shared_ptr<TestClass> test1 = std::make_shared<TestClass>();
       test1->key = "test1";
       std::shared_ptr<TestClass> test2 = std::make_shared<TestClass>();
       test2->key = "test2";
       map.emplace(test1->key, test1);
       map.emplace(test2->key, test2);
   
       map.forEachValue([&map](std::shared_ptr<TestClass> test) {
           test->print();
           map.remove(test->key);
       });
   }
   
   ```
   
   will result:
   
   ```shell
   /Users/baozi/workspace/github/pulsar-cpp/pulsar/pulsar-client-cpp/tests/main 
--gtest_filter=SchemaTest.ttt:SchemaTest/*.ttt:SchemaTest.ttt/*:*/SchemaTest.ttt/*:*/SchemaTest/*.ttt
 --gtest_color=no
   Testing started at 18:0009 ...
   test:test2
   Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
   
   ```
   



-- 
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]

Reply via email to