-
Notifications
You must be signed in to change notification settings - Fork 522
Description
Currently, std::default_random_engine is used in rclcpp_action/src/client_base.cpp. However, in GCC, this is implemented as minstd_rand0, which is a linear congruential generator (LCG). Due to its periodic nature, when actions are executed frequently, duplicate goal_id values can occur.
By default, goal_id is retained for 15 minutes, increasing the likelihood of duplication. In my program, where actions are executed continuously, an exception occurs due to this issue. Through testing, I found that the same goal_id was generated twice within a 10-minute span.
This results in the following error in rcl_action_accept_new_goal():
rcl_action\src\rcl_action\action_server.c
if (rcl_action_server_goal_exists(action_server, goal_info)) { RCL_SET_ERROR_MSG("goal ID already exists"); return NULL; }
In ServerBase::execute_goal_request_received, this leads to an exception being thrown:
rclcpp_action\src\server.cpp
{ std::lock_guard<std::recursive_mutex> lock(pimpl_->action_server_reentrant_mutex_); rcl_handle = rcl_action_accept_new_goal(pimpl_->action_server_.get(), &goal_info); } if (!rcl_handle) { throw std::runtime_error("Failed to accept new goal\n"); }
Proposed Change
Replacing std::default_random_engine with std::mt19937 in client_base.cpp will eliminate the periodicity issue, ensuring that goal_id values do not duplicate.
Expected Benefits
- Prevents duplicate goal_id collisions in frequently executed actions.
- Improves the randomness quality of generated IDs.
- Avoids unexpected exceptions related to duplicate goal acceptance.