Skip to content

Commit 4e871be

Browse files
Janosch MachowinskiJanosch Machowinski
authored andcommitted
fix: Fixed race condition in action server between is_ready and take_data and execute
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. This commit fixed this by - Introducing a data queue that is filled in is_ready - take_data from now only pops the front element of the data queue - A backlog of events if held in num_unreported_events_ which will be reported by future calls of is_ready Signed-off-by: Janosch Machowinski <[email protected]>
1 parent 4691063 commit 4e871be

File tree

3 files changed

+232
-112
lines changed

3 files changed

+232
-112
lines changed

rclcpp_action/include/rclcpp_action/server.hpp

Lines changed: 10 additions & 3 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"
@@ -279,19 +280,25 @@ class ServerBase : public rclcpp::Waitable
279280
/// \internal
280281
RCLCPP_ACTION_PUBLIC
281282
void
282-
execute_goal_request_received(std::shared_ptr<void> & data);
283+
execute_goal_request_received(
284+
rcl_ret_t ret, rcl_action_goal_info_t goal_info, rmw_request_id_t request_header,
285+
std::shared_ptr<void> message);
283286

284287
/// Handle a request to cancel goals on the server
285288
/// \internal
286289
RCLCPP_ACTION_PUBLIC
287290
void
288-
execute_cancel_request_received(std::shared_ptr<void> & data);
291+
execute_cancel_request_received(
292+
rcl_ret_t ret, std::shared_ptr<action_msgs::srv::CancelGoal::Request> request,
293+
rmw_request_id_t request_header);
289294

290295
/// Handle a request to get the result of an action
291296
/// \internal
292297
RCLCPP_ACTION_PUBLIC
293298
void
294-
execute_result_request_received(std::shared_ptr<void> & data);
299+
execute_result_request_received(
300+
rcl_ret_t ret, std::shared_ptr<void> result_request,
301+
rmw_request_id_t request_header);
295302

296303
/// Handle a timeout indicating a completed goal should be forgotten by the server
297304
/// \internal

0 commit comments

Comments
 (0)