Skip to content

Commit

Permalink
fix select nullptr front when dispatcherMessage caused coredump
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Nov 19, 2024
1 parent 3d8c75f commit 7e0cf85
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cpp/ppc-framework/protocol/INodeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class INodeInfo
virtual void decode(bcos::bytesConstRef data) = 0;

virtual void setFront(std::shared_ptr<ppc::front::IFrontClient>&& front) = 0;
virtual std::shared_ptr<ppc::front::IFrontClient> const& getFront() const = 0;
virtual std::shared_ptr<ppc::front::IFrontClient> getFront() const = 0;

virtual bool equal(INodeInfo::Ptr const& info)
{
Expand Down
9 changes: 8 additions & 1 deletion cpp/wedpr-protocol/protobuf/src/NodeInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,14 @@ class NodeInfoImpl : public INodeInfo

void setFront(std::shared_ptr<ppc::front::IFrontClient>&& front) override
{
bcos::WriteGuard l(x_front);
m_front = std::move(front);
}
std::shared_ptr<ppc::front::IFrontClient> const& getFront() const override { return m_front; }
std::shared_ptr<ppc::front::IFrontClient> getFront() const override
{
bcos::ReadGuard l(x_front);
return m_front;
}

void toJson(Json::Value& jsonObject) const override;

Expand All @@ -142,6 +147,8 @@ class NodeInfoImpl : public INodeInfo

private:
std::shared_ptr<ppc::front::IFrontClient> m_front;
mutable bcos::SharedMutex x_front;

std::set<std::string> m_components;
mutable bcos::SharedMutex x_components;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ std::vector<std::shared_ptr<ppc::front::IFrontClient>> GatewayNodeInfoImpl::choo
bcos::ReadGuard l(x_nodeList);
for (auto const& it : m_nodeList)
{
if (it.second->components().count(component))
auto front = it.second->getFront();
if (front && it.second->components().count(component))
{
result.emplace_back(it.second->getFront());
result.emplace_back(front);
}
if (!result.empty() && !selectAll)
{
Expand All @@ -175,7 +176,11 @@ std::vector<std::shared_ptr<ppc::front::IFrontClient>> GatewayNodeInfoImpl::choo
bcos::ReadGuard l(x_nodeList);
for (auto const& it : m_nodeList)
{
result.emplace_back(it.second->getFront());
auto front = it.second->getFront();
if (front)
{
result.emplace_back(front);
}
if (!result.empty() && !selectAll)
{
break;
Expand All @@ -194,7 +199,11 @@ std::vector<std::shared_ptr<ppc::front::IFrontClient>> GatewayNodeInfoImpl::choo
bcos::ReadGuard l(x_nodeList);
for (auto const& it : m_nodeList)
{
result.emplace_back(it.second->getFront());
auto front = it.second->getFront();
if (front)
{
result.emplace_back(front);
}
}
return result;
}
Expand All @@ -210,7 +219,11 @@ std::vector<std::shared_ptr<ppc::front::IFrontClient>> GatewayNodeInfoImpl::choo
// ignore the fromNode
if (selectedNode != nullptr && selectedNode->nodeID().toBytes() != fromNode)
{
result.emplace_back(selectedNode->getFront());
auto front = selectedNode->getFront();
if (front)
{
result.emplace_back(front);
}
}
if (!result.empty() && !selectAll)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ bool LocalRouter::dispatcherMessage(
int i = 0;
for (auto const& front : frontList)
{
if (!front)
{
continue;
}
if (i == 0)
{
front->onReceiveMessage(msg->msg(), callback);
Expand Down Expand Up @@ -153,9 +157,10 @@ std::vector<ppc::front::IFrontClient::Ptr> LocalRouter::chooseReceiver(
case (uint16_t)RouteType::ROUTE_THROUGH_NODEID:
{
auto gatewayInfo = m_routerInfo->nodeInfo(msg->header()->optionalField()->dstNode());
if (gatewayInfo != nullptr)
auto front = gatewayInfo->getFront();
if (gatewayInfo != nullptr && front)
{
receivers.emplace_back(gatewayInfo->getFront());
receivers.emplace_back(front);
}
return receivers;
}
Expand Down

0 comments on commit 7e0cf85

Please sign in to comment.