Shutting down composable nodes: component_container segfaults after SIGINT (Ctrl+C causes exit code -11)

asked 2021-02-04 15:48:35 -0500

phillipov gravatar image

In ROS2 Foxy, I am launching a single ComposableNode in a ComposableNodeContainer from a launch.py file. In "normal" ROS2 situations (with plain single-process nodes), I would press Ctrl+C (SIGINT) in the terminal to shut down all nodes. I expected my ComposableNode to shut down cleanly, with exit code 0.

However, this causes the ComposableNodeContainer executable named component_container to segfault with exit code -11, which is quite the unclean death. It even reports a crash to Ubuntu.

USERNAME@HOSTNAME:~/ros_ws$ ros2 launch my_pkg hello.launch.py 
[INFO] [launch]: All log files can be found below /home/USERNAME/.ros/log/2021-02-04-10-24-32-711854-HOSTNAME-44448
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [component_container-1]: process started with pid [44461]
[component_container-1] [INFO] [1612463073.081532882] [my_container]: Load Library: /home/USERNAME/ros_ws/install/my_pkg/lib/libmy_pkg.so
[component_container-1] [INFO] [1612463073.087369252] [my_container]: Found class: rclcpp_components::NodeFactoryTemplate<my_pkg::my_node>
[component_container-1] [INFO] [1612463073.087421457] [my_container]: Instantiate class: rclcpp_components::NodeFactoryTemplate<my_pkg::my_node>
[component_container-1] Starting my_node.
[INFO] [launch_ros.actions.load_composable_nodes]: Loaded node '/my_node' in container '/my_container'
^C[WARNING] [launch]: user interrupted with ctrl-c (SIGINT)
[component_container-1] [INFO] [1612463075.018685500] [rclcpp]: signal_handler(signal_value=2)
[component_container-1] Shut down my_node.
[ERROR] [component_container-1]: process has died [pid 44461, exit code -11, cmd '/opt/ros/foxy/lib/rclcpp_components/component_container --ros-args -r __node:=my_container -r __ns:=/'].

Here is my Python launch file:

import launch
from launch_ros.actions import ComposableNodeContainer
from launch_ros.descriptions import ComposableNode
import launch.actions
import launch.substitutions
import launch_ros.actions

def generate_launch_description():
    container = ComposableNodeContainer(
        name='my_container',
        package='rclcpp_components',
        namespace='',
        executable='component_container',
        composable_node_descriptions=[
            ComposableNode(
                package='my_pkg',
                plugin='my_pkg::my_node',
                name='my_node'
            )
        ],
        output='screen'
    )

    return launch.LaunchDescription([container])

How do I allow the component_container to shut down cleanly when my ComposableNode shuts down? Am I not supposed to shut down my nodes using Ctrl+C? Perhaps this is a problem with my launch file; I do not know how to specify a clean ComposableNodeContainer shutdown in ROS2.

For additional information, my one node does nothing except print to the terminal when it starts and when it shuts down.

my_node::my_node(const NodeOptions& options)
: Node("my_node", options)
{
    std::cout << "Starting my_node." << std::endl;
    on_shutdown([&]
    {
        my_node::shutdown_callback();
    });
}

void my_node::shutdown_callback()
{
    std::cout << "Shut down my_node." << std::endl;
}

System: ROS2 Foxy / Ubuntu 20.04 5.8.0-41-generic / Intel Core i7-1065G7

edit retag flag offensive close merge delete