Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid deleting XmlRpcClient's while they are being still in use on another thread #1013

Merged
merged 2 commits into from
Apr 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions clients/roscpp/src/libros/xmlrpc_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,31 @@ void XMLRPCManager::shutdown()
server_.close();

// kill the last few clients that were started in the shutdown process
for (V_CachedXmlRpcClient::iterator i = clients_.begin();
i != clients_.end(); ++i)
{
for (int wait_count = 0; i->in_use_ && wait_count < 10; wait_count++)
boost::mutex::scoped_lock lock(clients_mutex_);

for (V_CachedXmlRpcClient::iterator i = clients_.begin();
i != clients_.end();)
{
ROSCPP_LOG_DEBUG("waiting for xmlrpc connection to finish...");
ros::WallDuration(0.01).sleep();
if (!i->in_use_)
{
i->client_->close();
delete i->client_;
i = clients_.erase(i);
}
else
{
++i;
}
}

i->client_->close();
delete i->client_;
}

clients_.clear();
// Wait for the clients that are in use to finish and remove themselves from clients_
for (int wait_count = 0; !clients_.empty() && wait_count < 10; wait_count++)
{
ROSCPP_LOG_DEBUG("waiting for xmlrpc connection to finish...");
ros::WallDuration(0.01).sleep();
}

boost::mutex::scoped_lock lock(functions_mutex_);
functions_.clear();
Expand Down Expand Up @@ -369,7 +380,17 @@ void XMLRPCManager::releaseXMLRPCClient(XmlRpcClient *c)
{
if (c == i->client_)
{
i->in_use_ = false;
if (shutting_down_)
{
// if we are shutting down we won't be re-using the client
i->client_->close();
delete i->client_;
clients_.erase(i);
}
else
{
i->in_use_ = false;
}
break;
}
}
Expand Down