Skip to content

Commit

Permalink
Agent crash@ DiscoveryServiceClient::Subscribe
Browse files Browse the repository at this point in the history
<Agent::ControllerXmpp> task and <xmpp::StateMachine> are not
exclusive and hence add/delete to inuse_service_list_ can happen
in parallel and hence reason for the crash, protect this
vector manipulation via a mutex.

Note: <http client> and <xmpp::StateMachine> where most
manipulation of inuse_service_list_ happen is already exclusive.

Change-Id: I48a4cd4c0c85e328c65fd7908608be7b7c0e9562
Closes-Bug:1608791
  • Loading branch information
nipak committed Aug 9, 2016
1 parent 8ae2e7a commit 3ddee66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/discovery/client/discovery_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -825,19 +825,22 @@ void DiscoveryServiceClient::Subscribe(std::string serviceName) {
}
}

if (resp->inuse_service_list_.size()) {
pugi::xml_node node_service = pugi->FindNode(serviceName);
if (!pugi->IsNull(node_service)) {
pugi->ReadNode(serviceName); //SetContext
pugi->AddChildNode("service-in-use-list", "");
std::vector<boost::asio::ip::tcp::endpoint>::iterator it;
for (it = resp->inuse_service_list_.begin();
it != resp->inuse_service_list_.end(); it++) {
boost::asio::ip::tcp::endpoint ep = *it;
std::string pub_id =
resp->GetPublisherId(ep.address().to_string());
pugi->AddChildNode("publisher-id", pub_id);
pugi->ReadNode("service-in-use-list");
{
tbb::mutex::scoped_lock lock(mutex_);
if (resp->inuse_service_list_.size()) {
pugi::xml_node node_service = pugi->FindNode(serviceName);
if (!pugi->IsNull(node_service)) {
pugi->ReadNode(serviceName); //SetContext
pugi->AddChildNode("service-in-use-list", "");
std::vector<boost::asio::ip::tcp::endpoint>::iterator it;
for (it = resp->inuse_service_list_.begin();
it != resp->inuse_service_list_.end(); it++) {
boost::asio::ip::tcp::endpoint ep = *it;
std::string pub_id =
resp->GetPublisherId(ep.address().to_string());
pugi->AddChildNode("publisher-id", pub_id);
pugi->ReadNode("service-in-use-list");
}
}
}
}
Expand Down Expand Up @@ -1235,6 +1238,7 @@ void DiscoveryServiceClient::AddSubscribeInUseServiceList(

DSSubscribeResponse *resp = GetSubscribeResponse(serviceName);
if (resp) {
tbb::mutex::scoped_lock lock(mutex_);
resp->AddInUseServiceList(ep);
}
}
Expand All @@ -1244,6 +1248,7 @@ void DiscoveryServiceClient::DeleteSubscribeInUseServiceList(

DSSubscribeResponse *resp = GetSubscribeResponse(serviceName);
if (resp) {
tbb::mutex::scoped_lock lock(mutex_);
resp->DeleteInUseServiceList(ep);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/discovery/client/discovery_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class DiscoveryServiceClient {
std::string subscriber_name_;
int heartbeat_interval_;
std::string local_addr_;
tbb::mutex mutex_;
};

#endif // __DISCOVERY_SERVICE_CLIENT_H__

0 comments on commit 3ddee66

Please sign in to comment.