Skip to content

Commit d429bd0

Browse files
Fix race condition crash in estimate_path_traveling (open-rmf#486)
Signed-off-by: Adharsh Venkatachalam <adharshvenkat@users.noreply.github.com> Co-authored-by: Adharsh Venkatachalam <adharshvenkat@users.noreply.github.com>
1 parent 88581db commit d429bd0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

rmf_fleet_adapter/src/rmf_fleet_adapter/estimation.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ void estimate_path_traveling(
8888
assert(!state.path.empty());
8989

9090
const std::size_t remaining_count = state.path.size();
91+
92+
// Add bounds checking to prevent race condition crash
93+
if (remaining_count > info.waypoints.size()) {
94+
RCLCPP_WARN(
95+
node->get_logger(),
96+
"Race condition detected: Robot reports %zu remaining waypoints but RMF plan only "
97+
"has %zu waypoints. This happens when robot still reports from old path while RMF has "
98+
"replanned a shorter path. Robot: %s, Fleet: %s. Using fallback estimation.",
99+
remaining_count, info.waypoints.size(),
100+
info.robot_name.c_str(), info.fleet_name.c_str());
101+
102+
// Fallback: estimate based on robot's current location relative to final goal
103+
estimate_state(node, state.location, info);
104+
return;
105+
}
106+
91107
const std::size_t i_target_wp = info.waypoints.size() - remaining_count;
92108
info.target_plan_index = i_target_wp;
93109
const auto& target_wp = info.waypoints.at(i_target_wp);

0 commit comments

Comments
 (0)