Skip to content

Commit 75b56b7

Browse files
authored
fix select nullptr front when dispatcherMessage caused coredump (#95)
* fix waitress version * fix select nullptr front when dispatcherMessage caused coredump * fix model can't send message when some gateway down
1 parent 85a9419 commit 75b56b7

File tree

7 files changed

+49
-16
lines changed

7 files changed

+49
-16
lines changed

cpp/ppc-framework/protocol/INodeInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class INodeInfo
5757
virtual void decode(bcos::bytesConstRef data) = 0;
5858

5959
virtual void setFront(std::shared_ptr<ppc::front::IFrontClient>&& front) = 0;
60-
virtual std::shared_ptr<ppc::front::IFrontClient> const& getFront() const = 0;
60+
virtual std::shared_ptr<ppc::front::IFrontClient> getFront() const = 0;
6161

6262
virtual bool equal(INodeInfo::Ptr const& info)
6363
{

cpp/wedpr-protocol/grpc/client/GrpcClient.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ bcos::Error::Ptr GrpcClient::broadCast(
7575
std::function<bcos::Error::Ptr(ChannelInfo const& channel)> callback)
7676
{
7777
auto result = std::make_shared<bcos::Error>(0, "");
78+
int successCount = 0;
7879
for (auto const& channel : m_broadcastChannels)
7980
{
8081
try
@@ -91,6 +92,10 @@ bcos::Error::Ptr GrpcClient::broadCast(
9192
result->setErrorCode(error->errorCode());
9293
result->setErrorMessage(result->errorMessage() + error->errorMessage() + "; ");
9394
}
95+
else
96+
{
97+
successCount++;
98+
}
9499
}
95100
catch (std::exception const& e)
96101
{
@@ -99,5 +104,10 @@ bcos::Error::Ptr GrpcClient::broadCast(
99104
<< LOG_KV("error", boost::diagnostic_information(e));
100105
}
101106
}
107+
// at least one success
108+
if (successCount > 0)
109+
{
110+
return std::make_shared<bcos::Error>(0, "success");
111+
}
102112
return result;
103113
}

cpp/wedpr-protocol/protobuf/src/NodeInfoImpl.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,14 @@ class NodeInfoImpl : public INodeInfo
117117

118118
void setFront(std::shared_ptr<ppc::front::IFrontClient>&& front) override
119119
{
120+
bcos::WriteGuard l(x_front);
120121
m_front = std::move(front);
121122
}
122-
std::shared_ptr<ppc::front::IFrontClient> const& getFront() const override { return m_front; }
123+
std::shared_ptr<ppc::front::IFrontClient> getFront() const override
124+
{
125+
bcos::ReadGuard l(x_front);
126+
return m_front;
127+
}
123128

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

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

143148
private:
144149
std::shared_ptr<ppc::front::IFrontClient> m_front;
150+
mutable bcos::SharedMutex x_front;
151+
145152
std::set<std::string> m_components;
146153
mutable bcos::SharedMutex x_components;
147154

cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfoImpl.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ std::vector<std::shared_ptr<ppc::front::IFrontClient>> GatewayNodeInfoImpl::choo
155155
bcos::ReadGuard l(x_nodeList);
156156
for (auto const& it : m_nodeList)
157157
{
158-
if (it.second->components().count(component))
158+
auto front = it.second->getFront();
159+
if (front && it.second->components().count(component))
159160
{
160-
result.emplace_back(it.second->getFront());
161+
result.emplace_back(front);
161162
}
162163
if (!result.empty() && !selectAll)
163164
{
@@ -175,7 +176,11 @@ std::vector<std::shared_ptr<ppc::front::IFrontClient>> GatewayNodeInfoImpl::choo
175176
bcos::ReadGuard l(x_nodeList);
176177
for (auto const& it : m_nodeList)
177178
{
178-
result.emplace_back(it.second->getFront());
179+
auto front = it.second->getFront();
180+
if (front)
181+
{
182+
result.emplace_back(front);
183+
}
179184
if (!result.empty() && !selectAll)
180185
{
181186
break;
@@ -194,7 +199,11 @@ std::vector<std::shared_ptr<ppc::front::IFrontClient>> GatewayNodeInfoImpl::choo
194199
bcos::ReadGuard l(x_nodeList);
195200
for (auto const& it : m_nodeList)
196201
{
197-
result.emplace_back(it.second->getFront());
202+
auto front = it.second->getFront();
203+
if (front)
204+
{
205+
result.emplace_back(front);
206+
}
198207
}
199208
return result;
200209
}
@@ -210,7 +219,11 @@ std::vector<std::shared_ptr<ppc::front::IFrontClient>> GatewayNodeInfoImpl::choo
210219
// ignore the fromNode
211220
if (selectedNode != nullptr && selectedNode->nodeID().toBytes() != fromNode)
212221
{
213-
result.emplace_back(selectedNode->getFront());
222+
auto front = selectedNode->getFront();
223+
if (front)
224+
{
225+
result.emplace_back(front);
226+
}
214227
}
215228
if (!result.empty() && !selectAll)
216229
{

cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayRouterManager.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ void GatewayRouterManager::onReceiveNodeSeqMessage(MessageFace::Ptr msg, WsSessi
103103
auto statusSeq =
104104
boost::asio::detail::socket_ops::network_to_host_long(*((uint32_t*)msg->payload()->data()));
105105
auto p2pMessage = std::dynamic_pointer_cast<P2PMessage>(msg);
106-
auto const& from = (p2pMessage->header()->srcGwNode().size() > 0) ?
107-
p2pMessage->header()->srcGwNode() :
108-
session->nodeId();
106+
auto from = (p2pMessage->header()->srcGwNode().size() > 0) ? p2pMessage->header()->srcGwNode() :
107+
session->nodeId();
109108
auto statusSeqChanged = statusChanged(from, statusSeq);
110109
if (!statusSeqChanged)
111110
{
@@ -151,9 +150,8 @@ void GatewayRouterManager::onReceiveRequestNodeStatusMsg(
151150
MessageFace::Ptr msg, WsSession::Ptr session)
152151
{
153152
auto p2pMessage = std::dynamic_pointer_cast<P2PMessage>(msg);
154-
auto const& from = (!p2pMessage->header()->srcGwNode().empty()) ?
155-
p2pMessage->header()->srcGwNode() :
156-
session->nodeId();
153+
auto from = (!p2pMessage->header()->srcGwNode().empty()) ? p2pMessage->header()->srcGwNode() :
154+
session->nodeId();
157155

158156
auto nodeStatusData = m_localRouter->generateNodeStatus();
159157
if (!nodeStatusData)

cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/LocalRouter.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ bool LocalRouter::dispatcherMessage(
9898
int i = 0;
9999
for (auto const& front : frontList)
100100
{
101+
if (!front)
102+
{
103+
continue;
104+
}
101105
if (i == 0)
102106
{
103107
front->onReceiveMessage(msg->msg(), callback);
@@ -153,9 +157,10 @@ std::vector<ppc::front::IFrontClient::Ptr> LocalRouter::chooseReceiver(
153157
case (uint16_t)RouteType::ROUTE_THROUGH_NODEID:
154158
{
155159
auto gatewayInfo = m_routerInfo->nodeInfo(msg->header()->optionalField()->dstNode());
156-
if (gatewayInfo != nullptr)
160+
auto front = gatewayInfo ? gatewayInfo->getFront() : nullptr;
161+
if (gatewayInfo != nullptr && front)
157162
{
158-
receivers.emplace_back(gatewayInfo->getFront());
163+
receivers.emplace_back(front);
159164
}
160165
return receivers;
161166
}

python/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pycryptodome==3.9.9
2727
pyjwt
2828
pyyaml
2929
mysqlclient==2.1.0
30-
waitress==3.0.1
30+
waitress==3.0.0
3131
sqlparse~=0.4.1
3232
toolz~=0.11.1
3333
tenacity==7.0.0

0 commit comments

Comments
 (0)