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


##########
pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc:
##########
@@ -125,33 +144,37 @@ Future<Result, Consumer> 
MultiTopicsConsumerImpl::subscribeOneTopicAsync(const s
     }
 
     // subscribe for each partition, when all partitions completed, complete 
promise
-    
lookupServicePtr_->getPartitionMetadataAsync(topicName).addListener(std::bind(
-        &MultiTopicsConsumerImpl::subscribeTopicPartitions, 
shared_from_this(), std::placeholders::_1,
-        std::placeholders::_2, topicName, subscriptionName_, conf_, 
topicPromise));
+    Lock lock(mutex_);
+    auto entry = topicsPartitions_.find(topic);
+    lock.unlock();

Review Comment:
   You should not unlock here. `entry` is an iterator that references a node 
from the map (`topicsPartitions_`). The iterator acts like a pointer, which 
means the object which an iterator references could be modified.
   
   For example,
   
   ```c++
       std::map<int, int> m;
       m[1] = 100;
       const auto entry = m.find(1);
       std::cout << entry->second << std::endl;  // 100 as expected
   
       m[1] = 200;  // assume it happened in another thread
       std::cout << entry->second << std::endl;  // 200
   ```



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