@@ -56,6 +56,16 @@ using namespace ASIO::ip;
5656
5757namespace pulsar {
5858
59+ namespace {
60+ static std::ostream& operator <<(std::ostream& os, const tcp::resolver::results_type& results) {
61+ for (const auto & entry : results) {
62+ const auto & ep = entry.endpoint ();
63+ os << ep.address ().to_string () << " :" << ep.port () << " " ;
64+ }
65+ return os;
66+ }
67+ } // anonymous namespace
68+
5969using proto::BaseCommand;
6070
6171static const uint32_t DefaultBufferSize = 64 * 1024 ;
@@ -486,7 +496,7 @@ void ClientConnection::handleTcpConnected(const ASIO_ERROR& err, const tcp::endp
486496 handleHandshake (ASIO_SUCCESS);
487497 }
488498 } else {
489- LOG_ERROR (cnxString_ << " Failed to establish connection: " << err.message ());
499+ LOG_ERROR (cnxString_ << " Failed to establish connection to " << endpoint << " : " << err.message ());
490500 if (err == ASIO::error::operation_aborted) {
491501 close ();
492502 } else {
@@ -603,16 +613,25 @@ void ClientConnection::handleResolve(ASIO_ERROR err, const tcp::resolver::result
603613 return ;
604614 }
605615
616+ if (!results.empty ()) {
617+ LOG_DEBUG (cnxString_ << " Resolved " << results.size () << " endpoints" );
618+ for (const auto & entry : results) {
619+ const auto & ep = entry.endpoint ();
620+ LOG_DEBUG (cnxString_ << " " << ep.address ().to_string () << " :" << ep.port ());
621+ }
622+ }
623+
606624 auto weakSelf = weak_from_this ();
607- connectTimeoutTask_->setCallback ([weakSelf](const PeriodicTask::ErrorCode& ec) {
625+ connectTimeoutTask_->setCallback ([weakSelf, results = tcp::resolver::results_type (results)](
626+ const PeriodicTask::ErrorCode& ec) {
608627 ClientConnectionPtr ptr = weakSelf.lock ();
609628 if (!ptr) {
610- // Connection was already destroyed
629+ LOG_DEBUG ( " Connect timeout callback skipped: connection was already destroyed" );
611630 return ;
612631 }
613632
614633 if (ptr->state_ != Ready) {
615- LOG_ERROR (ptr->cnxString_ << " Connection was not established in "
634+ LOG_ERROR (ptr->cnxString_ << " Connection to " << results << " was not established in "
616635 << ptr->connectTimeoutTask_ ->getPeriodMs () << " ms, close the socket" );
617636 PeriodicTask::ErrorCode err;
618637 ptr->socket_ ->close (err);
@@ -1212,20 +1231,23 @@ Future<Result, ResponseData> ClientConnection::sendRequestWithId(const SharedBuf
12121231void ClientConnection::handleRequestTimeout (const ASIO_ERROR& ec,
12131232 const PendingRequestData& pendingRequestData) {
12141233 if (!ec && !pendingRequestData.hasGotResponse ->load ()) {
1234+ LOG_WARN (cnxString_ << " Network request timeout to broker, remote: " << physicalAddress_);
12151235 pendingRequestData.promise .setFailed (ResultTimeout);
12161236 }
12171237}
12181238
12191239void ClientConnection::handleLookupTimeout (const ASIO_ERROR& ec,
12201240 const LookupRequestData& pendingRequestData) {
12211241 if (!ec) {
1242+ LOG_WARN (cnxString_ << " Lookup request timeout to broker, remote: " << physicalAddress_);
12221243 pendingRequestData.promise ->setFailed (ResultTimeout);
12231244 }
12241245}
12251246
12261247void ClientConnection::handleGetLastMessageIdTimeout (const ASIO_ERROR& ec,
12271248 const ClientConnection::LastMessageIdRequestData& data) {
12281249 if (!ec) {
1250+ LOG_WARN (cnxString_ << " GetLastMessageId request timeout to broker, remote: " << physicalAddress_);
12291251 data.promise ->setFailed (ResultTimeout);
12301252 }
12311253}
0 commit comments