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


##########
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:
   @RobertIndie @BewareMyPower The current implementation removes or cleans up 
the `consumers_` in the `handSingleConsumerClose` method, so there is a risk 
that the nullptr.
   
   
https://github.com/apache/pulsar/blob/7f6972766f1f8a989f477cbb3085d0660be53bd8/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc#L369-L375
   
   
https://github.com/apache/pulsar/blob/7f6972766f1f8a989f477cbb3085d0660be53bd8/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc#L392
   
   
https://github.com/apache/pulsar/blob/7f6972766f1f8a989f477cbb3085d0660be53bd8/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc#L409
   
   So use `toPairVector` to re-copy a collection for traversal.  Is there a 
better way?
   



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