Skip to content

Commit b8f567b

Browse files
author
Kaven Yau
committed
Fix deadlock issue that caused by other mutexes locked in CancelCallback
1 parent ec70642 commit b8f567b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

rclcpp_action/include/rclcpp_action/server.hpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,16 +356,20 @@ class Server : public ServerBase, public std::enable_shared_from_this<Server<Act
356356
CancelResponse
357357
call_handle_cancel_callback(const GoalUUID & uuid) override
358358
{
359-
std::lock_guard<std::mutex> lock(goal_handles_mutex_);
359+
std::shared_ptr<ServerGoalHandle<ActionT>> goal_handle;
360+
{
361+
std::lock_guard<std::mutex> lock(goal_handles_mutex_);
362+
auto element = goal_handles_.find(uuid);
363+
if (element != goal_handles_.end()) {
364+
goal_handle = element->second.lock();
365+
}
366+
}
367+
360368
CancelResponse resp = CancelResponse::REJECT;
361-
auto element = goal_handles_.find(uuid);
362-
if (element != goal_handles_.end()) {
363-
std::shared_ptr<ServerGoalHandle<ActionT>> goal_handle = element->second.lock();
364-
if (goal_handle) {
365-
resp = handle_cancel_(goal_handle);
366-
if (CancelResponse::ACCEPT == resp) {
367-
goal_handle->_cancel_goal();
368-
}
369+
if (goal_handle) {
370+
resp = handle_cancel_(goal_handle);
371+
if (CancelResponse::ACCEPT == resp) {
372+
goal_handle->_cancel_goal();
369373
}
370374
}
371375
return resp;

0 commit comments

Comments
 (0)