-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
planner_data
access outside mutex lock inside behavior_path_planner_node
#2495
Comments
@VRichardJP |
Thank you, I will test it. However, I am not convinced copying the
If you do this:
Then,
You may have the |
@VRichardJP |
@VRichardJP does this solve this bug report? #2510 |
I am sorry, I still think there is a concurrency issue. The autoware.universe/planning/behavior_path_planner/src/behavior_path_planner_node.cpp Line 686 in 72a27d3
Nothing prevents another function from modifying autoware.universe/planning/behavior_path_planner/src/behavior_path_planner_node.cpp Lines 916 to 920 in 72a27d3
There are only 3 ways to solve the issue:
I think the second or third option are simpler. Actually, most callbacks are already in the same group. I think only the timer callback to autoware.universe/planning/behavior_path_planner/src/behavior_path_planner_node.cpp Lines 175 to 176 in 72a27d3
|
@VRichardJP is this issue solved by these two PRs above? |
@xmfcx In the current state, the code has no concurrent memory access. This was also true before the few changes. But this is just an illusion, as the inherent problem has yet to be solved. My comment above still holds: the inner data of It can be verified with this small example: diff --git a/launch/tier4_planning_launch/launch/scenario_planning/lane_driving/behavior_planning/behavior_planning.launch.py b/launch/tier4_planning_launch/launch/scenario_planning/lane_driving/behavior_planning/behavior_planning.launch.py
index 293d8bebf2..7fc7eb8299 100644
--- a/launch/tier4_planning_launch/launch/scenario_planning/lane_driving/behavior_planning/behavior_planning.launch.py
+++ b/launch/tier4_planning_launch/launch/scenario_planning/lane_driving/behavior_planning/behavior_planning.launch.py
@@ -225,6 +225,7 @@ def launch_setup(context, *args, **kwargs):
behavior_velocity_planner_component,
],
output="screen",
+ prefix="gnome-terminal --",
)
# This condition is true if run_out module is enabled and its detection method is Points
diff --git a/planning/behavior_path_planner/include/behavior_path_planner/behavior_path_planner_node.hpp b/planning/behavior_path_planner/include/behavior_path_planner/behavior_path_planner_node.hpp
index 45eab08040..60d25fc023 100644
--- a/planning/behavior_path_planner/include/behavior_path_planner/behavior_path_planner_node.hpp
+++ b/planning/behavior_path_planner/include/behavior_path_planner/behavior_path_planner_node.hpp
@@ -103,6 +103,8 @@ private:
rclcpp::Publisher<MarkerArray>::SharedPtr bound_publisher_;
rclcpp::Publisher<PoseWithUuidStamped>::SharedPtr modified_goal_publisher_;
rclcpp::TimerBase::SharedPtr timer_;
+ rclcpp::TimerBase::SharedPtr timer2_;
+ rclcpp::CallbackGroup::SharedPtr timer2_cb_group_;
std::map<std::string, rclcpp::Publisher<Path>::SharedPtr> path_candidate_publishers_;
diff --git a/planning/behavior_path_planner/src/behavior_path_planner_node.cpp b/planning/behavior_path_planner/src/behavior_path_planner_node.cpp
index 11f89c06e0..feb5d78026 100644
--- a/planning/behavior_path_planner/src/behavior_path_planner_node.cpp
+++ b/planning/behavior_path_planner/src/behavior_path_planner_node.cpp
@@ -26,6 +26,7 @@
#include <memory>
#include <string>
+#include <thread>
#include <utility>
#include <vector>
@@ -191,6 +192,21 @@ BehaviorPathPlannerNode::BehaviorPathPlannerNode(const rclcpp::NodeOptions & nod
const auto period_ns = rclcpp::Rate(planning_hz).period();
timer_ = rclcpp::create_timer(
this, get_clock(), period_ns, std::bind(&BehaviorPathPlannerNode::run, this));
+ timer2_cb_group_ = create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
+ timer2_ = rclcpp::create_timer(
+ this, get_clock(), rclcpp::Rate(1.0).period(), [&]() {
+ const std::lock_guard<std::mutex> lock(mutex_pd_);
+ if (has_received_map_) {
+ std::cout << "Updating Map" << std::endl;
+ planner_data_->route_handler->setMap(*map_ptr_);
+ has_received_map_ = false;
+ }
+ if (has_received_route_) {
+ std::cout << "Updating Route" << std::endl;
+ planner_data_->route_handler->setRoute(*route_ptr_);
+ has_received_route_ = false;
+ }
+ }, timer2_cb_group_);
}
}
@@ -783,6 +799,15 @@ void BehaviorPathPlannerNode::run()
// create latest planner data
const auto planner_data = createLatestPlannerData();
+ for (;;) {
+ // planner_data route size should never change.
+ printf("planner_data:%zu planner_data_:%zu\n",
+ planner_data->route_handler->getRouteLanelets().size(),
+ planner_data_->route_handler->getRouteLanelets().size());
+ using namespace std::chrono_literals;
+ std::this_thread::sleep_for(1s);
+ }
+
// run behavior planner
const auto output = bt_manager_->run(planner_data);
diff --git a/planning/route_handler/include/route_handler/route_handler.hpp b/planning/route_handler/include/route_handler/route_handler.hpp
index 591b436151..588c560b9e 100644
--- a/planning/route_handler/include/route_handler/route_handler.hpp
+++ b/planning/route_handler/include/route_handler/route_handler.hpp
@@ -292,6 +292,7 @@ public:
double getLaneChangeableDistance(
const Pose & current_pose, const LaneChangeDirection & direction) const;
lanelet::ConstPolygon3d getIntersectionAreaById(const lanelet::Id id) const;
+ lanelet::ConstLanelets getRouteLanelets() const;
private:
// MUST
@@ -336,7 +337,6 @@ private:
const lanelet::ConstLanelet & lanelet, lanelet::ConstLanelet * right_lanelet) const;
bool getLeftLaneletWithinRoute(
const lanelet::ConstLanelet & lanelet, lanelet::ConstLanelet * left_lanelet) const;
- lanelet::ConstLanelets getRouteLanelets() const;
lanelet::ConstLanelets getLaneletSequenceUpTo(
const lanelet::ConstLanelet & lanelet,
const double min_length = std::numeric_limits<double>::max()) const; With these changes:
If everything is safe, the printing loop should always display the same value for Compile, source, then run autoware in the planning simulator. For example:
Set a start and goal points. In the terminal window, you can see the current route size displayed every second. If you change the goal point so the route has more/less lanelets, you can see the both |
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]>
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]>
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]>
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix
solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix
* fix(behavior_path_planner): concurrency issue solves #2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix * style(pre-commit): autofix --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Fixed by #2933 |
* fix(behavior_path_planner): concurrency issue solves autowarefoundation#2495 Signed-off-by: Vincent Richard <[email protected]> Signed-off-by: Vincent Richard <[email protected]> style(pre-commit): autofix * style(pre-commit): autofix --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Checklist
Description
Found the exact same issue than #2422 here:
autoware.universe/planning/behavior_path_planner/src/behavior_path_planner_node.cpp
Line 657 in f1a9a96
The data is accessed outside the
mutex_pd_
lock guardWhile working on my PR, I reset the
route_handler
internal data after a new route has just arrived. The data is only left uninitialized while the new route is being checked/loaded (which happens in the same callback). However I got the following segfault, showing that another thread tried to access the data at the same time:Expected behavior
no concurrent access
Actual behavior
unprotected access
Steps to reproduce
N/A
Versions
No response
Possible causes
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: