Skip to content

Commit

Permalink
<fix>(ws,front): add tbb task group wait in destruct method.
Browse files Browse the repository at this point in the history
  • Loading branch information
kyonRay committed Jan 11, 2024
1 parent 4ba671f commit bc52209
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions bcos-boostssl/bcos-boostssl/websocket/WsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions bcos-boostssl/bcos-boostssl/websocket/WsSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class WsSession : public std::enable_shared_from_this<WsSession>,
using Ptrs = std::vector<std::shared_ptr<WsSession>>;

public:
WsSession(tbb::task_group& taskGroup, std::string _moduleName = "DEFAULT");
explicit WsSession(tbb::task_group& taskGroup, std::string _moduleName = "DEFAULT");

virtual ~WsSession() noexcept
{
Expand Down Expand Up @@ -149,7 +149,7 @@ class WsSession : public std::enable_shared_from_this<WsSession>,
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;
Expand Down
1 change: 1 addition & 0 deletions bcos-front/bcos-front/FrontService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ FrontService::FrontService()
FrontService::~FrontService() noexcept
{
stop();
m_asyncGroup.wait();
FRONT_LOG(INFO) << LOG_DESC("~FrontService") << LOG_KV("this", this);
}

Expand Down
26 changes: 13 additions & 13 deletions bcos-rpc/bcos-rpc/amop/AMOPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
#include <bcos-utilities/Timer.h>
#include <servant/Application.h>

#include <utility>

#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<AMOPClient>
{
Expand All @@ -38,20 +39,20 @@ class AMOPClient : public std::enable_shared_from_this<AMOPClient>
AMOPClient(std::shared_ptr<boostssl::ws::WsService> _wsService,
std::shared_ptr<bcos::boostssl::MessageFaceFactory> _wsMessageFactory,
std::shared_ptr<bcos::protocol::AMOPRequestFactory> _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
m_gatewayStatusDetector = std::make_shared<Timer>(5000, "gatewayDetector");
m_gatewayStatusDetector->registerTimeoutHandler([this]() { pingGatewayAndNotifyTopics(); });
}

virtual ~AMOPClient() {}
virtual ~AMOPClient() = default;
/**
* @brief receive amop request message from the gateway
*
Expand Down Expand Up @@ -89,7 +90,7 @@ class AMOPClient : public std::enable_shared_from_this<AMOPClient>
if (m_gatewayStatusDetector)
{
auto activeEndPoints = getActiveGatewayEndPoints();
if (activeEndPoints.size() == 0)
if (activeEndPoints.empty())
{
m_gatewayActivated.store(false);
}
Expand Down Expand Up @@ -189,5 +190,4 @@ class AMOPClient : public std::enable_shared_from_this<AMOPClient>
std::atomic_bool m_gatewayActivated = {true};
std::atomic_bool m_notifyTopicSuccess = {true};
};
} // namespace rpc
} // namespace bcos
} // namespace bcos::rpc
12 changes: 6 additions & 6 deletions bcos-rpc/bcos-rpc/amop/AirAMOPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#pragma once
#include "AMOPClient.h"

namespace bcos
{
namespace rpc
#include <utility>

namespace bcos::rpc
{
class AirAMOPClient : public AMOPClient
{
Expand All @@ -33,7 +33,8 @@ class AirAMOPClient : public AMOPClient
std::shared_ptr<bcos::boostssl::MessageFaceFactory> _wsMessageFactory,
std::shared_ptr<bcos::protocol::AMOPRequestFactory> _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
Expand Down Expand Up @@ -74,5 +75,4 @@ class AirAMOPClient : public AMOPClient
});
}
};
} // namespace rpc
} // namespace bcos
} // namespace bcos::rpc

0 comments on commit bc52209

Please sign in to comment.