Skip to content

Commit 5bc9abd

Browse files
wjwwoodJanosch Machowinski
authored andcommitted
fix: Fixed race condition in action server between is_ready and take" (ros2#2495)
Some background information: is_ready, take_data and execute data may be called from different threads in any order. The code in the old state expected them to be called in series, without interruption. This lead to multiple race conditions, as the state of the pimpl objects was altered by the three functions in a non thread safe way. Signed-off-by: Janosch Machowinski <[email protected]> Signed-off-by: William Woodall <[email protected]> Signed-off-by: Janosch Machowinski <[email protected]> Co-authored-by: Janosch Machowinski <[email protected]> Signed-off-by: Janosch Machowinski <[email protected]>
1 parent d599f9e commit 5bc9abd

File tree

4 files changed

+441
-244
lines changed

4 files changed

+441
-244
lines changed

rclcpp_action/include/rclcpp_action/server.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <unordered_map>
2323
#include <utility>
2424

25+
#include "action_msgs/srv/cancel_goal.hpp"
2526
#include "rcl/event_callback.h"
2627
#include "rcl_action/action_server.h"
2728
#include "rosidl_runtime_c/action_type_support_struct.h"
@@ -345,7 +346,8 @@ class Server : public ServerBase, public std::enable_shared_from_this<Server<Act
345346

346347
/// Signature of a callback that accepts or rejects goal requests.
347348
using GoalCallback = std::function<GoalResponse(
348-
const GoalUUID &, std::shared_ptr<const typename ActionT::Goal>)>;
349+
const GoalUUID &,
350+
std::shared_ptr<const typename ActionT::Goal>)>;
349351
/// Signature of a callback that accepts or rejects requests to cancel a goal.
350352
using CancelCallback = std::function<CancelResponse(std::shared_ptr<ServerGoalHandle<ActionT>>)>;
351353
/// Signature of a callback that is used to notify when the goal has been accepted.
@@ -455,7 +457,8 @@ class Server : public ServerBase, public std::enable_shared_from_this<Server<Act
455457
void
456458
call_goal_accepted_callback(
457459
std::shared_ptr<rcl_action_goal_handle_t> rcl_goal_handle,
458-
GoalUUID uuid, std::shared_ptr<void> goal_request_message) override
460+
GoalUUID uuid,
461+
std::shared_ptr<void> goal_request_message) override
459462
{
460463
std::shared_ptr<ServerGoalHandle<ActionT>> goal_handle;
461464
std::weak_ptr<Server<ActionT>> weak_this = this->shared_from_this();

0 commit comments

Comments
 (0)