From 45d9c410a06ebb8aae7f46d24af8e43db4208c16 Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Thu, 11 Jan 2024 20:51:15 +0800 Subject: [PATCH] (ws,front): add tbb task group wait in destruct method. (#4166) --- .../bcos-boostssl/websocket/WsService.cpp | 1 + .../bcos-boostssl/websocket/WsSession.h | 4 +-- bcos-front/bcos-front/FrontService.cpp | 1 + bcos-rpc/bcos-rpc/amop/AMOPClient.h | 26 +++++++++---------- bcos-rpc/bcos-rpc/amop/AirAMOPClient.h | 12 ++++----- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/bcos-boostssl/bcos-boostssl/websocket/WsService.cpp b/bcos-boostssl/bcos-boostssl/websocket/WsService.cpp index 35e96b437d..4343cc1f34 100644 --- a/bcos-boostssl/bcos-boostssl/websocket/WsService.cpp +++ b/bcos-boostssl/bcos-boostssl/websocket/WsService.cpp @@ -52,6 +52,7 @@ WsService::WsService(std::string _moduleName) : m_moduleName(std::move(_moduleNa WsService::~WsService() { stop(); + m_taskGroup.wait(); WEBSOCKET_SERVICE(INFO) << LOG_KV("[DELOBJ][WsService]", this); } diff --git a/bcos-boostssl/bcos-boostssl/websocket/WsSession.h b/bcos-boostssl/bcos-boostssl/websocket/WsSession.h index 879064ed45..1b3b7d5e60 100644 --- a/bcos-boostssl/bcos-boostssl/websocket/WsSession.h +++ b/bcos-boostssl/bcos-boostssl/websocket/WsSession.h @@ -51,7 +51,7 @@ class WsSession : public std::enable_shared_from_this, using Ptrs = std::vector>; public: - WsSession(tbb::task_group& taskGroup, std::string _moduleName = "DEFAULT"); + explicit WsSession(tbb::task_group& taskGroup, std::string _moduleName = "DEFAULT"); virtual ~WsSession() noexcept { @@ -149,7 +149,7 @@ class WsSession : public std::enable_shared_from_this, std::string moduleName() { return m_moduleName; } void setModuleName(std::string _moduleName) { m_moduleName = std::move(_moduleName); } - bool needCheckRspPacket() { return m_needCheckRspPacket; } + bool needCheckRspPacket() const { return m_needCheckRspPacket; } void setNeedCheckRspPacket(bool _needCheckRespPacket) { m_needCheckRspPacket = _needCheckRespPacket; diff --git a/bcos-front/bcos-front/FrontService.cpp b/bcos-front/bcos-front/FrontService.cpp index ae391f462e..68856f23aa 100644 --- a/bcos-front/bcos-front/FrontService.cpp +++ b/bcos-front/bcos-front/FrontService.cpp @@ -44,6 +44,7 @@ FrontService::FrontService() FrontService::~FrontService() noexcept { stop(); + m_asyncGroup.wait(); FRONT_LOG(INFO) << LOG_DESC("~FrontService") << LOG_KV("this", this); } diff --git a/bcos-rpc/bcos-rpc/amop/AMOPClient.h b/bcos-rpc/bcos-rpc/amop/AMOPClient.h index 2923f6d043..7bd3bcde6d 100644 --- a/bcos-rpc/bcos-rpc/amop/AMOPClient.h +++ b/bcos-rpc/bcos-rpc/amop/AMOPClient.h @@ -26,10 +26,11 @@ #include #include +#include + #define AMOP_CLIENT_LOG(level) BCOS_LOG(level) << LOG_BADGE("AMOPClient") -namespace bcos -{ -namespace rpc + +namespace bcos::rpc { class AMOPClient : public std::enable_shared_from_this { @@ -38,12 +39,12 @@ class AMOPClient : public std::enable_shared_from_this AMOPClient(std::shared_ptr _wsService, std::shared_ptr _wsMessageFactory, std::shared_ptr _requestFactory, - bcos::gateway::GatewayInterface::Ptr _gateway, std::string const& _gatewayServiceName) - : m_wsService(_wsService), - m_wsMessageFactory(_wsMessageFactory), - m_requestFactory(_requestFactory), - m_gateway(_gateway), - m_gatewayServiceName(_gatewayServiceName) + bcos::gateway::GatewayInterface::Ptr _gateway, std::string _gatewayServiceName) + : m_wsService(std::move(_wsService)), + m_wsMessageFactory(std::move(_wsMessageFactory)), + m_requestFactory(std::move(_requestFactory)), + m_gateway(std::move(_gateway)), + m_gatewayServiceName(std::move(_gatewayServiceName)) { initMsgHandler(); // create gatewayStatusDetector to detect status of gateway periodically @@ -51,7 +52,7 @@ class AMOPClient : public std::enable_shared_from_this m_gatewayStatusDetector->registerTimeoutHandler([this]() { pingGatewayAndNotifyTopics(); }); } - virtual ~AMOPClient() {} + virtual ~AMOPClient() = default; /** * @brief receive amop request message from the gateway * @@ -89,7 +90,7 @@ class AMOPClient : public std::enable_shared_from_this if (m_gatewayStatusDetector) { auto activeEndPoints = getActiveGatewayEndPoints(); - if (activeEndPoints.size() == 0) + if (activeEndPoints.empty()) { m_gatewayActivated.store(false); } @@ -189,5 +190,4 @@ class AMOPClient : public std::enable_shared_from_this std::atomic_bool m_gatewayActivated = {true}; std::atomic_bool m_notifyTopicSuccess = {true}; }; -} // namespace rpc -} // namespace bcos \ No newline at end of file +} // namespace bcos::rpc diff --git a/bcos-rpc/bcos-rpc/amop/AirAMOPClient.h b/bcos-rpc/bcos-rpc/amop/AirAMOPClient.h index 278ebd3398..1837797bca 100644 --- a/bcos-rpc/bcos-rpc/amop/AirAMOPClient.h +++ b/bcos-rpc/bcos-rpc/amop/AirAMOPClient.h @@ -21,9 +21,9 @@ #pragma once #include "AMOPClient.h" -namespace bcos -{ -namespace rpc +#include + +namespace bcos::rpc { class AirAMOPClient : public AMOPClient { @@ -33,7 +33,8 @@ class AirAMOPClient : public AMOPClient std::shared_ptr _wsMessageFactory, std::shared_ptr _requestFactory, bcos::gateway::GatewayInterface::Ptr _gateway) - : AMOPClient(_wsService, _wsMessageFactory, _requestFactory, _gateway, "localGateway") + : AMOPClient(std::move(_wsService), std::move(_wsMessageFactory), std::move(_requestFactory), + std::move(_gateway), "localGateway") {} // Note: must with empty implementation to in case of start the m_gatewayStatusDetector @@ -74,5 +75,4 @@ class AirAMOPClient : public AMOPClient }); } }; -} // namespace rpc -} // namespace bcos \ No newline at end of file +} // namespace bcos::rpc