Skip to content

Commit 131a11b

Browse files
authored
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 <[email protected]>
1 parent 29308dc commit 131a11b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

rclcpp_action/include/rclcpp_action/client.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,21 +368,23 @@ class Client : public ClientBase
368368
// Do not use std::make_shared as friendship cannot be forwarded.
369369
std::shared_ptr<GoalHandle> goal_handle(
370370
new GoalHandle(goal_info, options.feedback_callback, options.result_callback));
371+
{
372+
std::lock_guard<std::mutex> guard(goal_handles_mutex_);
373+
goal_handles_[goal_handle->get_goal_id()] = goal_handle;
374+
}
375+
promise->set_value(goal_handle);
376+
if (options.goal_response_callback) {
377+
options.goal_response_callback(future);
378+
}
379+
371380
if (options.result_callback) {
372381
try {
373382
this->make_result_aware(goal_handle);
374383
} catch (...) {
375384
promise->set_exception(std::current_exception());
376-
options.goal_response_callback(future);
377385
return;
378386
}
379387
}
380-
std::lock_guard<std::mutex> guard(goal_handles_mutex_);
381-
goal_handles_[goal_handle->get_goal_id()] = goal_handle;
382-
promise->set_value(goal_handle);
383-
if (options.goal_response_callback) {
384-
options.goal_response_callback(future);
385-
}
386388
});
387389
return future;
388390
}

0 commit comments

Comments
 (0)