Skip to content

AMCL core dumps due to a race condition when used with the map server. #4537

@techtasie

Description

@techtasie

Bug report

Required Info:

  • Operating System:
    • fedora 40
  • ROS2 Version: jazzy
    • jazzy
  • Version or commit hash: 1.3.1
    • from source: no changes from the source.
  • DDS implementation:
    • cyclonedds

Steps to reproduce issue

In the core dump, you see that map_ can be a null pointer and therefore you get an unhandled null pointer exception.
Uncommenting those lines circumvented the crash for us:

diff --color -ur navigation2-release-release-jazzy-nav2_amcl-1.3.1-1/src/amcl_node.cpp navigation2-release-release-jazzy-nav2_amcl-1.3.1-1-new/src/amcl_node.cpp
--- navigation2-release-release-jazzy-nav2_amcl-1.3.1-1/src/amcl_node.cpp	2024-06-25 20:01:09.000000000 +0200
+++ navigation2-release-release-jazzy-nav2_amcl-1.3.1-1-new/src/amcl_node.cpp	2024-07-15 17:43:12.792477289 +0200
@@ -540,13 +540,13 @@
       global_frame_id_.c_str());
     return;
   }
-  if (abs(msg->pose.pose.position.x) > map_->size_x ||
-    abs(msg->pose.pose.position.y) > map_->size_y)
-  {
-    RCLCPP_ERROR(
-      get_logger(), "Received initialpose from message is out of the size of map. Rejecting.");
-    return;
-  }
+  // if (abs(msg->pose.pose.position.x) > map_->size_x ||
+  //   abs(msg->pose.pose.position.y) > map_->size_y)
+  // {
+  //   RCLCPP_ERROR(
+  //     get_logger(), "Received initialpose from message is out of the size of map. Rejecting.");
+  //   return;
+  // }
 
   // Overriding last published pose to initial pose
   last_published_pose_ = *msg;

There is a race condition between the receiving of the map topic subscriber and setting the initial pose. On our robot, this race condition almost always happens but could be hard to reproduce on other setups.

Expected behavior

AMCL localization at initial pose or at least not crashing.

Actual behavior

AMCL coredumps

Additional information

I have attached our core dump. For the core dump, I rebuilt only AMCL in Debug mode; everything else was built as ReleaseWithDebug.
core.amcl.1000.c11f12581e0949ccb1dcd9e3d30b45d0.13740.1721053490000000.tar.gz
We are using a custom map server that may experience a slight delay when starting up. Therefore, AMCL could be launched without a map.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions