Skip to content

Commit b6ecf7d

Browse files
Janosch MachowinskiJanosch Machowinski
authored andcommitted
feat(Client): Added function to drop a goal handle in a thread safe way
This function allows us to drop the handle in a locked context. If we do not do this within a lock, there will be a race condition between the deletion of the shared_ptr of the handle and the result / feedback callbacks. Signed-off-by: Janosch Machowinski <[email protected]>
1 parent 6a7fe7f commit b6ecf7d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

rclcpp_action/include/rclcpp_action/client.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,21 @@ class Client : public ClientBase
562562
return async_cancel(cancel_request, cancel_callback);
563563
}
564564

565+
void drop_goal_handle(typename GoalHandle::SharedPtr goal_handle)
566+
{
567+
std::lock_guard<std::mutex> guard(goal_handles_mutex_);
568+
const GoalUUID & goal_id = goal_handle->get_goal_id();
569+
if (goal_handles_.count(goal_id) == 0) {
570+
// someone else already deleted the entry
571+
// e.g. the result callback
572+
RCLCPP_DEBUG(
573+
this->get_logger(),
574+
"Given goal is unknown. Ignoring...");
575+
return;
576+
}
577+
goal_handles_.erase(goal_id);
578+
}
579+
565580
/// Asynchronously request all goals at or before a specified time be canceled.
566581
/**
567582
* \param[in] stamp The timestamp for the cancel goal request.

0 commit comments

Comments
 (0)