You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "RobertIndie (via GitHub)" <gi...@apache.org> on 2023/03/01 08:12:12 UTC

[GitHub] [pulsar-client-cpp] RobertIndie commented on a diff in pull request #203: [fix] Handle exceptions when creating timers when fd limit is reached

RobertIndie commented on code in PR #203:
URL: https://github.com/apache/pulsar-client-cpp/pull/203#discussion_r1121317645


##########
lib/PartitionedProducerImpl.cc:
##########
@@ -439,26 +439,40 @@ void PartitionedProducerImpl::handleGetPartitions(Result result,
             LOG_INFO("new partition count: " << newNumPartitions);
             topicMetadata_.reset(new TopicMetadataImpl(newNumPartitions));
 
+            std::vector<ProducerImplPtr> producers;
+            auto lazy = conf_.getLazyStartPartitionedProducers() &&
+                        conf_.getAccessMode() == ProducerConfiguration::Shared;
             for (unsigned int i = currentNumPartitions; i < newNumPartitions; i++) {
-                auto lazy = conf_.getLazyStartPartitionedProducers() &&
-                            conf_.getAccessMode() == ProducerConfiguration::Shared;
-                auto producer = newInternalProducer(i, lazy);
-
+                ProducerImplPtr producer;
+                try {
+                    producer = newInternalProducer(i, lazy);
+                } catch (const std::runtime_error& e) {
+                    LOG_ERROR("Failed to create producer for partition " << i << ": " << e.what());
+                    producers.clear();
+                    break;
+                }
+                producers.emplace_back(producer);
+            }
+            if (producers.empty()) {
+                runPartitionUpdateTask();
+                return;
+            }
+            for (unsigned int i = 0; i < producers.size(); i++) {
+                auto&& producer = producers[i];
+                producers_.emplace_back(producer);
                 if (!lazy) {
                     producer->start();
                 }
-                producers_.push_back(producer);
             }
             producersLock.unlock();
             // `runPartitionUpdateTask()` will be called in `handleSinglePartitionProducerCreated()`
             interceptors_->onPartitionsChange(getTopic(), newNumPartitions);
-            return;
+            runPartitionUpdateTask();

Review Comment:
   As for the comment at line 468, seems we don't need to call `runPartitionUpdateTask` here



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org