From 58ad811f7c9defb7e5708c6bff45dcc0b9770adb Mon Sep 17 00:00:00 2001 From: RikeVoltz Date: Fri, 8 May 2020 13:47:28 +0300 Subject: [PATCH 1/2] Changed closedTime to closedTimeDuration to support correct atomic initialization --- hazelcast/include/hazelcast/client/connection/Connection.h | 2 +- hazelcast/src/hazelcast/client/network.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hazelcast/include/hazelcast/client/connection/Connection.h b/hazelcast/include/hazelcast/client/connection/Connection.h index 3eb4ad704a..0494c6e049 100644 --- a/hazelcast/include/hazelcast/client/connection/Connection.h +++ b/hazelcast/include/hazelcast/client/connection/Connection.h @@ -142,7 +142,7 @@ namespace hazelcast { void innerClose(); std::chrono::steady_clock::time_point startTime; - std::atomic closedTime; + std::atomic closedTimeDuration; spi::ClientContext &clientContext; protocol::IMessageHandler &invocationService; std::unique_ptr socket; diff --git a/hazelcast/src/hazelcast/client/network.cpp b/hazelcast/src/hazelcast/client/network.cpp index 1eba4e4d84..b98cffa204 100644 --- a/hazelcast/src/hazelcast/client/network.cpp +++ b/hazelcast/src/hazelcast/client/network.cpp @@ -902,6 +902,7 @@ namespace hazelcast { boost::asio::ip::tcp::resolver &resolver) : readHandler(*this, 16 << 10), startTime(std::chrono::steady_clock::now()), + closedTimeDuration(), clientContext(clientContext), invocationService(clientContext.getInvocationService()), authFuture(authFuture), @@ -945,7 +946,7 @@ namespace hazelcast { return; } - closedTime.store(std::chrono::steady_clock::now()); + closedTimeDuration.store(std::chrono::steady_clock::now().time_since_epoch()); closeCause = cause; closeReason = reason; @@ -1112,7 +1113,7 @@ namespace hazelcast { os << "null"; } os << ", lastReadTime=" << util::StringUtil::timeToString(conn.lastReadTime()) - << ", closedTime=" << util::StringUtil::timeToString(conn.closedTime) + << ", closedTime=" << util::StringUtil::timeToString(std::chrono::steady_clock::time_point(conn.closedTimeDuration)) << ", connected server version=" << conn.connectedServerVersionString << '}'; From 902c08f59ed5b94851c1df4c720fa56774217a9e Mon Sep 17 00:00:00 2001 From: RikeVoltz Date: Fri, 8 May 2020 16:01:28 +0300 Subject: [PATCH 2/2] Added fix for lastReadTime too --- hazelcast/include/hazelcast/client/connection/ReadHandler.h | 2 +- hazelcast/src/hazelcast/client/network.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hazelcast/include/hazelcast/client/connection/ReadHandler.h b/hazelcast/include/hazelcast/client/connection/ReadHandler.h index 2334e7db10..15d34e7abb 100644 --- a/hazelcast/include/hazelcast/client/connection/ReadHandler.h +++ b/hazelcast/include/hazelcast/client/connection/ReadHandler.h @@ -60,7 +60,7 @@ namespace hazelcast { private: protocol::ClientMessageBuilder builder; - std::atomic lastReadTime; + std::atomic lastReadTimeDuration; }; } } diff --git a/hazelcast/src/hazelcast/client/network.cpp b/hazelcast/src/hazelcast/client/network.cpp index b98cffa204..169b91142d 100644 --- a/hazelcast/src/hazelcast/client/network.cpp +++ b/hazelcast/src/hazelcast/client/network.cpp @@ -863,7 +863,7 @@ namespace hazelcast { ReadHandler::ReadHandler(Connection &connection, size_t bufferSize) : buffer(new char[bufferSize]), byteBuffer(buffer, bufferSize), builder(connection), - lastReadTime(std::chrono::steady_clock::now()) { + lastReadTimeDuration(std::chrono::steady_clock::now().time_since_epoch()) { } ReadHandler::~ReadHandler() { @@ -871,7 +871,7 @@ namespace hazelcast { } void ReadHandler::handle() { - lastReadTime = std::chrono::steady_clock::now(); + lastReadTimeDuration = std::chrono::steady_clock::now().time_since_epoch(); if (byteBuffer.position() == 0) return; @@ -891,7 +891,7 @@ namespace hazelcast { } const std::chrono::steady_clock::time_point ReadHandler::getLastReadTime() const { - return lastReadTime; + return std::chrono::steady_clock::time_point(lastReadTimeDuration); } Connection::Connection(const Address &address, spi::ClientContext &clientContext, int connectionId,