Skip to content

Shutdown cleanly on SIGTERM #1704

Closed

Description

@emersonknapp

Feature request

Feature description

The rclcpp Context shuts down gracefully on a SIGINT, which is generally received via a Ctrl+C interaction. However, another reasonable way on Linux to try to shut down processes is via a SIGTERM - according to GNU Documentation:

The SIGTERM signal is a generic signal used to cause program termination. Unlike SIGKILL, this signal can be blocked, handled, and ignored. It is the normal way to politely ask a program to terminate.

It seems reasonable to me to have rclcpp generate a clean shutdown on SIGTERM by default. This could be another InitOptions member like shutdown_on_sigint, defaulting to true.

For context - I am trying to support a use case where rosbag2 recording processes are controlled via SIGTERM. In order for the recording to finish cleanly and generate all the metadata, it needs to have a graceful shutdown rather than immediate termination. I can handle this at the rosbag2 level, but given the preexisting SIGINT handling in the ros2 client, it makes sense to me to extend that handling to support this case.

Implementation considerations

Should be pretty easy, install signal handlers the same way we do for SIGINT.

Activity

  1. wjwwood commented on Jul 1, 2021

    @wjwwood
    Member

    Seems reasonable to me, but it is a significant change in behavior which might affect how things with with say launch right now. So it would need to be thoroughly tested.

    @ros2/team for feedback.

  2. added
    enhancement
    help wanted
    on Jul 1, 2021
  3. emersonknapp commented on Jul 2, 2021

    @emersonknapp
    CollaboratorAuthor

    significant change in behavior

    We could also consider default to false, in which case the default behavior would not change. Though I think I'd prefer to default to true.

  4. clalancette commented on Jul 6, 2021

    @clalancette
    Contributor

    👍 to handling SIGTERM as well, though I agree with William that it needs thorough testing. Messing with the signal handlers is always fragile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions