Skip to content

[ROS2] Keep rclcpp loaded until process exit - #1109

Merged
jhanca-robotecai merged 2 commits into
o3de:developmentfrom
RobotecAI:jh/fix_tests
Oct 23, 2026
Merged

jhanca-robotecai merged 2 commits into
o3de:developmentfrom
RobotecAI:jh/fix_tests

Conversation

@jhanca-robotecai

@jhanca-robotecai jhanca-robotecai commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

With ROS 2 Lyrical, processes that unload the ROS2 gem crash with SIGSEGV during process exit. The cause is in ROS 2: rmw_implementation and rcl_logging_implementation unload their plugin libraries (librmw_fastrtps_cpp, librcl_logging_spdlog) during process exit, from a static destructor and an atexit() handler. When the ROS2 gem has been unloaded before, that plugin can be the last reference keeping the ROS 2 libraries loaded, so its unload also unmaps librmw_implementation / librcl_logging_implementation while their code is still running.

This PR makes ROS2SystemComponent::Init() mark the already loaded librclcpp.so as non-unloadable (dlopen(..., RTLD_NOLOAD | RTLD_NODELETE)), right before rclcpp::init(). rclcpp and everything it depends on, including both libraries above, then stay loaded until the process ends, so the exit-time unloads cannot unmap code that is still running. RTLD_NOLOAD only changes the flags of the library that is already loaded; nothing new is loaded. The ROS2 gem is Linux-only, so dlfcn.h is available.

How was this PR tested?

Ubuntu 26.04, ROS 2 Lyrical, clang 21, profile build of a project with the o3de-extras ROS 2 gems, engine 2705 (development based): tests pass with the fix;SimulationInterfaces.ROS2Tests with the dlopen call suppressed (LD_PRELOAD interposer): exit code 139 without.

@jhanca-robotecai

Copy link
Copy Markdown
Collaborator Author

Tests fail due to: #1106
Btw. CI in this repo tests only ROS 2 Humble.

@michalpelka

michalpelka commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

I would suggest:

  • add issues pointer (ROS2 repo) to source code - to remove it on some point.
  • assert return value, just in case (e.g. someone has a great idea to change librclcpp.so to smth else ).

@jhanca-robotecai
jhanca-robotecai marked this pull request as ready for review October 19, 2026 06:12
@jhanca-robotecai
jhanca-robotecai requested review from a team as code owners October 19, 2026 06:12
@byrcolin byrcolin added the sig/simulation Categorizes an issue or PR as relevant to SIG Simulation label Oct 20, 2026
Signed-off-by: Jan Hanca <jan.hanca@robotec.ai>
Signed-off-by: Jan Hanca <jan.hanca@robotec.ai>
@jhanca-robotecai

Copy link
Copy Markdown
Collaborator Author

Rebased on top of #1106 to ensure the tests pass.

@jhanca-robotecai
jhanca-robotecai merged commit 5f56565 into o3de:development Oct 23, 2026
3 checks passed
@jhanca-robotecai
jhanca-robotecai deleted the jh/fix_tests branch October 23, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sig/simulation Categorizes an issue or PR as relevant to SIG Simulation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants