Skip to content

Deadlock when handling signals (e.g. SIGTERM) #2982

@nugins99

Description

@nugins99

Generated by Generative AI

No response

Operating System:

Linux 4.18.0-553.81.1.el8_10.x86_64 #1 SMP Thu Oct 16 14:01:33 EDT 2025 x86_64 x86_64 x86_64 GNU/Linux

ROS version or commit hash:

HUMBLE

RMW implementation (if applicable):

rmw_fastrtps_cpp

RMW Configuration (if applicable):

No response

Client library (if applicable):

rclcpp

'ros2 doctor --report' output

Steps to reproduce issue

  1. Write a trivial ROS application that enters a spin() loop and in another thread does some file I/O
  2. Launch rclcpp application
  3. Use "kill" command to issue a SIGTERM
  4. Repeat until application hangs on shutdown. Depending on the amount of I/O, this bug may be hard to trigger requiring 100's or 1000's of attempts to trigger.

Expected behavior

Application should never deadlock on signal handler.

Actual behavior

Application deadlocks with the following stack trace.

> #0  0x00007fe61b7e215c in __lll_lock_wait_private () from /lib64/libc.so.6
> #1  0x00007fe61b90ab68 in __fprintf_chk () from /lib64/libc.so.6
> #2  0x00007fe61ce19adf in rcutils_logging_console_output_handler () from /opt/ros/humble/lib/librcutils.so
> #3  0x00007fe6231da396 in rcl_logging_multiple_output_handler () from /opt/ros/humble/lib/librcl.so
> #4  0x00007fe623b6ac26 in rclcpp_logging_output_handler () from /opt/ros/humble/lib/librclcpp.so
> #5  0x00007fe61ce19291 in rcutils_log () from /opt/ros/humble/lib/librcutils.so
> #6  0x00007fe623c22a15 in rclcpp::SignalHandler::signal_handler(int, siginfo_t*, void*) () from /opt/ros/humble/lib/librclcpp.so
> #7  <signal handler called>
> #8  0x00007fe61b844b7d in fwrite () from /lib64/libc.so.6
> #9  0x00007fe61c24a896 in std::ostream::write(char const*, long) () from /lib64/libstdc++.so.6

Additional information

The issue is that that the signal handler attempts to write a log message. Signal handlers should never do I/O.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions