Skip to content

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Oct 16, 2025

🦟 Bug fix

Summary

There scope of the mutex lock is unnecessarily large which causes deadlocks in service requests when running local callbacks. This PR uses the same approach as the Node::Request shown below to reduce the scope of the mutex:

//////////////////////////////////////////////////
template<typename RequestT, typename ReplyT>
bool Node::Request(
const std::string &_topic,
const RequestT &_request,
std::function<void(const ReplyT &_reply, const bool _result)> &_cb)
{
// Topic remapping.
std::string topic = _topic;
this->Options().TopicRemap(_topic, topic);
std::string fullyQualifiedTopic;
if (!TopicUtils::FullyQualifiedName(this->Options().Partition(),
this->Options().NameSpace(), topic, fullyQualifiedTopic))
{
std::cerr << "Service [" << topic << "] is not valid." << std::endl;
return false;
}
bool localResponserFound;
IRepHandlerPtr repHandler;
{
std::lock_guard<std::recursive_mutex> lk(this->Shared()->mutex);
localResponserFound = this->Shared()->repliers.FirstHandler(
fullyQualifiedTopic,
std::string(RequestT().GetTypeName()),
std::string(ReplyT().GetTypeName()),
repHandler);
}
// If the responser is within my process.
if (localResponserFound)
{
// There is a responser in my process, let's use it.
ReplyT rep;
bool result = repHandler->RunLocalCallback(_request, rep);
_cb(rep, result);
return true;
}

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers
  • Was GenAI used to generate this PR? If so, make sure to add "Generated-by" to your commits. (See this policy for more info.)

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by and Generated-by messages.


This is an automatic backport of pull request #671 done by [Mergify](https://mergify.com).

There scope of the mutex lock is unnecessarily large which causes deadlocks in service requests when running local callbacks

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
(cherry picked from commit 80b5a56)
@github-project-automation github-project-automation bot moved this from Inbox to In review in Core development Oct 16, 2025
@azeey azeey enabled auto-merge (rebase) October 16, 2025 15:51
@azeey azeey merged commit d8faacb into gz-transport13 Oct 16, 2025
9 of 10 checks passed
@azeey azeey deleted the mergify/bp/gz-transport13/pr-671 branch October 16, 2025 16:18
@github-project-automation github-project-automation bot moved this from In review to Done in Core development Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🎵 harmonic Gazebo Harmonic

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant