From 6ad644dbaf6b48f4ab1bd4900dd5febef3de11fd Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Thu, 23 May 2019 21:00:58 -0700 Subject: [PATCH] Guard against calling null goal response callback (#738) Also make sure to invoke the goal response callback before the result callback. Signed-off-by: Jacob Perron Signed-off-by: Siddharth Kucheria --- rclcpp_action/include/rclcpp_action/client.hpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/rclcpp_action/include/rclcpp_action/client.hpp b/rclcpp_action/include/rclcpp_action/client.hpp index 910f304a73..e2f7bad29c 100644 --- a/rclcpp_action/include/rclcpp_action/client.hpp +++ b/rclcpp_action/include/rclcpp_action/client.hpp @@ -368,21 +368,23 @@ class Client : public ClientBase // Do not use std::make_shared as friendship cannot be forwarded. std::shared_ptr goal_handle( new GoalHandle(goal_info, options.feedback_callback, options.result_callback)); + { + std::lock_guard guard(goal_handles_mutex_); + goal_handles_[goal_handle->get_goal_id()] = goal_handle; + } + promise->set_value(goal_handle); + if (options.goal_response_callback) { + options.goal_response_callback(future); + } + if (options.result_callback) { try { this->make_result_aware(goal_handle); } catch (...) { promise->set_exception(std::current_exception()); - options.goal_response_callback(future); return; } } - std::lock_guard guard(goal_handles_mutex_); - goal_handles_[goal_handle->get_goal_id()] = goal_handle; - promise->set_value(goal_handle); - if (options.goal_response_callback) { - options.goal_response_callback(future); - } }); return future; }