From be099afaf47125ab04d85a470900a5747c485ac9 Mon Sep 17 00:00:00 2001 From: Zike Yang Date: Fri, 23 Dec 2022 17:48:14 +0800 Subject: [PATCH 1/3] [fix] Fix log for connection disconnected expectedly --- include/pulsar/Result.h | 2 ++ lib/ClientConnection.cc | 6 +++++- lib/ConnectionPool.cc | 2 +- lib/Result.cc | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/pulsar/Result.h b/include/pulsar/Result.h index 0f7d8a8b..033f4cb3 100644 --- a/include/pulsar/Result.h +++ b/include/pulsar/Result.h @@ -92,6 +92,8 @@ enum Result ResultMemoryBufferIsFull, /// Client-wide memory limit has been reached ResultInterrupted, /// Interrupted while waiting to dequeue + + ResultDisconnected, /// Client connection has been disconnected }; // Return string representation of result code diff --git a/lib/ClientConnection.cc b/lib/ClientConnection.cc index 51a09f45..634042f1 100644 --- a/lib/ClientConnection.cc +++ b/lib/ClientConnection.cc @@ -1596,7 +1596,11 @@ void ClientConnection::close(Result result) { } lock.unlock(); - LOG_INFO(cnxString_ << "Connection closed with " << result); + if (result != ResultDisconnected) { + LOG_ERROR(cnxString_ << "Connection closed with " << result); + } else { + LOG_INFO(cnxString_ << "Connection disconnected"); + } for (ProducersMap::iterator it = producers.begin(); it != producers.end(); ++it) { HandlerBase::handleDisconnection(result, shared_from_this(), it->second); diff --git a/lib/ConnectionPool.cc b/lib/ConnectionPool.cc index 1c246d64..37c72b9e 100644 --- a/lib/ConnectionPool.cc +++ b/lib/ConnectionPool.cc @@ -53,7 +53,7 @@ bool ConnectionPool::close() { for (auto cnxIt = pool_.begin(); cnxIt != pool_.end(); cnxIt++) { ClientConnectionPtr cnx = cnxIt->second.lock(); if (cnx) { - cnx->close(); + cnx->close(ResultDisconnected); } } pool_.clear(); diff --git a/lib/Result.cc b/lib/Result.cc index 3533b1ec..f7156ac5 100644 --- a/lib/Result.cc +++ b/lib/Result.cc @@ -165,6 +165,9 @@ const char* strResult(Result result) { case ResultInterrupted: return "ResultInterrupted"; + + case ResultDisconnected: + return "ResultDisconnected"; }; // NOTE : Do not add default case in the switch above. In future if we get new cases for // ServerError and miss them in the switch above we would like to get notified. Adding From b66bf046aaa252d62eba64da2855a0128073d834 Mon Sep 17 00:00:00 2001 From: Zike Yang Date: Mon, 26 Dec 2022 16:48:55 +0800 Subject: [PATCH 2/3] fix test --- tests/ClientTest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ClientTest.cc b/tests/ClientTest.cc index a4abc3a9..07fe22fd 100644 --- a/tests/ClientTest.cc +++ b/tests/ClientTest.cc @@ -126,7 +126,7 @@ TEST(ClientTest, testConnectTimeout) { clientDefault.close(); ASSERT_EQ(futureDefault.wait_for(std::chrono::milliseconds(10)), std::future_status::ready); - ASSERT_EQ(futureDefault.get(), ResultConnectError); + ASSERT_EQ(futureDefault.get(), ResultDisconnected); } TEST(ClientTest, testGetNumberOfReferences) { From 93ed38fc678f9ea4c871da6f3369842d355989c1 Mon Sep 17 00:00:00 2001 From: Zike Yang Date: Wed, 28 Dec 2022 14:38:27 +0800 Subject: [PATCH 3/3] Apply comments. --- lib/ClientConnection.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ClientConnection.cc b/lib/ClientConnection.cc index 634042f1..e9726c2c 100644 --- a/lib/ClientConnection.cc +++ b/lib/ClientConnection.cc @@ -1596,7 +1596,7 @@ void ClientConnection::close(Result result) { } lock.unlock(); - if (result != ResultDisconnected) { + if (result != ResultDisconnected && result != ResultRetryable) { LOG_ERROR(cnxString_ << "Connection closed with " << result); } else { LOG_INFO(cnxString_ << "Connection disconnected");