How can I make ROS2 launch quit on node crash? [closed]
I'm launching multiple nodes using ROS2 launch. I want the whole system to come down if any of the node encounters an exception.
Right now, my launch file looks like this:
from os.path import join
import launch
import launch.actions
import launch.substitutions
import launch_ros.actions
from ament_index_python import get_package_share_directory
from launch.actions import LogInfo
from launch.event_handlers import OnProcessExit
def generate_launch_description():
emit_shutdown_action = launch.actions.Shutdown(reason='launch is shutting down')
ld = launch.LaunchDescription([
launch_ros.actions.Node(
package='node_1',
node_executable='node1',
),
launch_ros.actions.Node(
package="node_2",
node_executable='node_2',
# METHOD 1: Node on_exit attribute
on_exit=[LogInfo(msg=["Node 2 stopped. Stopping everything..."]),
emit_shutdown_action],
),
])
# METHOD 2: ProcessExit event handler
ld.add_action(launch.actions.RegisterEventHandler(event_handler=OnProcessExit(
on_exit=[LogInfo(msg=["A Node stopped. Stopping everything..."]),
emit_shutdown_action]
)))
return ld
Here, I'm trying to effectively catch an unexpected crash of a node in two ways:
- through the 'node_2' process on_exit attribute
- through the ProcessExit event handler
However, it appears my nodes raising exceptions does not initiate a shut down, and instead, after raising an exception I only receive a log like such:
[ERROR] [node_2]: process has died [pid 11784, exit code 1, cmd '[..]/node_2' ].
indicating that the launch system is aware of my node dying, although no shutdown was triggered.
What should I do to make the launch system shutdown when one of the nodes dies?
have you been able to find an answer to your question?
This was a long time ago so my memory isn't very clear, but I believe an update to ROS2 (probably Foxy) fixed the issue for me