Skip to content

Failure to quit ros2 launch via SIGINT #495

@felixdivo

Description

@felixdivo

Bug report

Required Info:

  • Operating System:
    • Ubuntu 20.04
  • Installation type:
    • binary: ros-foxy-desktop
  • Version or commit hash:
    • foxy, most recent
  • DDS implementation:
    • default
  • Client library (if applicable):
    • Python code, but no client library is used directly

Steps to reproduce issue

  1. Create simple launch file (any seems to do, but this one will work right away if the examples are installed):
#!/usr/bin/env python3

# Node launching
from launch import LaunchDescription
from launch_ros.actions import Node


def generate_launch_description() -> LaunchDescription:
    return LaunchDescription(
        [
            Node(
                package="examples_rclpy_minimal_publisher",
                executable="publisher_local_function",
                name="minimal_node",
            ),
        ]
    )
  1. Create a simple script to start the launch file problematically. I need this for automation of a test suite.
from signal import SIGINT
from subprocess import Popen
from time import sleep

# Do not set `stdout=PIPE, stderr=STDOUT`, instead inherit from parent
launch_file = "example_launch_common.py"
process = Popen(["ros2", "launch", launch_file, "--debug"], text=True)
# Give the launch process time to start up
sleep(3.0)

# Signal the child launch process to finish; like Ctrl+C
process.send_signal(SIGINT)
# Might raise a TimeoutExpired if it takes too long
return_code = process.wait(timeout=10)
print(f"return_code: {return_code}")

Expected behavior

The node is gracefully shut down (in probably way less than a second after issuing the SIGINT) and the exit code is zero.

Actual behavior

The node fails to exit and must be killed, leaving an orphan process and taking quite some time:

[ERROR] [publisher_local_function-1]: process[publisher_local_function-1] failed to terminate '5' seconds after receiving 'SIGINT', escalating to 'SIGTERM'

Also, why is the exit code zero in this case? I could not find any documentation on the exit codes.

Additional information

Using the launch Python API causes the same problem as the Popen approach above.

When calling the launch file via ros2 launch example_launch_common.py -d from the bash console and exiting via Ctrl+C, everything works fine. This means that in such a case, the node reacts to the shutdown signal, it shuts down immediately and the exit code of the launch command is zero.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions