ros2 / ros2/rclcpp

Composable node runtime error (undefined symbol) but normal Node has no issue

Open
#2,391 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
805
Forks
564
Avg merge
1d 17h
Merged PRs (30d)
27

Description

Bug report

Required Info:

  • Operating System:
    • Ubuntu 22.04
  • Installation type:
    • binaries
  • Version or commit hash:
    • humble
  • DDS implementation:
  • Client library (if applicable):
    • rclcpp

I am trying to call the python interpreter from a ComposableNode.
I have no issue doing a simple print(), but if I try to do import torch, the program crashes with an undefined symbol error.

terminate called after throwing an instance of 'pybind11::error_already_set'
  what():  ImportError: /usr/lib/python3.10/lib-dynload/_ctypes.cpython-310-x86_64-linux-gnu.so: undefined symbol: PyTuple_Type

At:
  /usr/lib/python3.10/ctypes/__init__.py(8): <module>
  <frozen importlib._bootstrap>(241): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(883): exec_module
  <frozen importlib._bootstrap>(703): _load_unlocked
  <frozen importlib._bootstrap>(1006): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1027): _find_and_load
  /home/mclement/.local/lib/python3.10/site-packages/torch/__init__.py(17): <module>
  <frozen importlib._bootstrap>(241): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(883): exec_module
  <frozen importlib._bootstrap>(703): _load_unlocked
  <frozen importlib._bootstrap>(1006): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1027): _find_and_load

There is no issue when doing this with a normal Node.

Steps to reproduce issue

I made a minimal example showcasing the issue in the following repository: https://github.com/maxime-clem/ros2_composable_node_bug

# requires python3-dev and pybind11-dev
git clone git@github.com:maxime-clem/ros2_composable_node_bug.git
cd ros2_composable_node_bug
colcon build
source install/setup.sh
ros2 run test_exe test_exe  # No issue
ros2 run test_node test_node  # No issue
ros2 run test_composable_node test_composable_node_exe  # undefined symbol error
Expected behavior

Composable node can use the python library without issue, similarly to a normal Node.

Actual behavior

Composable node crashes with an undefined symbol: PyTuple_Type error.

Additional information

I have confirmed the issue with another user so it does not appear to be en environment issue.
The only workaround found so far is to use dlopen("libpython3.10.so", RTLD_GLOBAL | RTLD_NOW) in the code of the ComposableNode.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by cloning the linked minimal repository and running its three colcon/ros2 commands to reproduce the failure. Compare the normal and composable node entry points, then investigate the reported Python symbol-loading behavior and dlopen workaround. Done means the composable node can import torch without crashing, matching the normal node.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
robotics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.