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


##########
pulsar-client-cpp/lib/ConsumerImpl.cc:
##########
@@ -1326,8 +1336,26 @@ void 
ConsumerImpl::getLastMessageIdAsync(BrokerGetLastMessageIdCallback callback
             callback(ResultUnsupportedVersionError, MessageId());
         }
     } else {
-        LOG_ERROR(getName() << " Client Connection not ready for Consumer");
-        callback(ResultNotConnected, MessageId());
+        TimeDuration next = std::min(remainTime, backoff->next());
+        if (next.total_milliseconds() <= 0) {
+            LOG_ERROR(getName() << " Client Connection not ready for 
Consumer");
+            callback(ResultNotConnected, MessageId());
+            return;
+        }
+        remainTime -= next;
+
+        timer->expires_from_now(next);
+
+        timer->async_wait([this, backoff, remainTime, timer, next,
+                           callback](const boost::system::error_code& ec) -> 
void {

Review Comment:
   It's better to capture `shared_from_this()` here because when the callback 
is executed, the reference count of `std::shared_ptr<ConsumerImpl>` might be 
zero so that `this` points to an invalid address. Capturing the 
`shared_from_this()` can extend the lifetime of the object to ensure `this` 
always points to a valid address.



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