Skip to content

fix: prevent double-shutdown in rclcpp::Context - #3220

Open
fujitatomoya wants to merge 2 commits into
rollingfrom
fujitatomoya/rolling/racy-context-shutdown
Open

fix: prevent double-shutdown in rclcpp::Context#3220
fujitatomoya wants to merge 2 commits into
rollingfrom
fujitatomoya/rolling/racy-context-shutdown

Conversation

@fujitatomoya

Copy link
Copy Markdown
Collaborator

Description

retarget #3216 to rolling and pull some tests from http://github.com/ros2/rclcpp/pull/3219

Fixes # (issue)

Is this user-facing behavior change?

Did you use Generative AI?

Additional Information

fishitiny and others added 2 commits August 11, 2026 11:28
The signal handler thread (deferred_signal_handler) and the main thread
may both call Context::shutdown() during Ctrl-C, causing a double-free
or heap corruption in the underlying rcl_context_t and glibc.

Add an atomic flag is_shutting_down_ to ensure only the first call to
shutdown() proceeds; subsequent calls return immediately.

Steps to reproduce:
1. Launch any ROS 2 node with shutdown_on_signal=true
2. Press Ctrl-C
3. Observe SIGABRT in rclcpp::Context::shutdown() called from
   rclcpp::SignalHandler::deferred_signal_handler()

GDB backtrace from core dump:
  Thread 1: raise() -> abort()
    -> rclcpp::Context::shutdown()
    -> rclcpp::SignalHandler::deferred_signal_handler()

Signed-off-by: fishitiny <fishitiny@users.noreply.github.com>
(cherry picked from commit 599f3b8)

Adaptation for rolling: reset is_shutting_down_ in Context::init() so
that shutdown() works again after the context is re-initialized.

Signed-off-by: Tomoya Fujita <fujita.tomoya@triorb.co.jp>
Signed-off-by: Tomoya Fujita <fujita.tomoya@triorb.co.jp>
@mergify

mergify Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@fujitatomoya fujitatomoya left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is ABI breaking change, we will not backport this to downstream.
for backports, we will use #3219

@fujitatomoya

Copy link
Copy Markdown
Collaborator Author

Pulls: #3220
Gist: https://gist.githubusercontent.com/fujitatomoya/de91f7d37226d2a379118c2a2b51453b/raw/8c3e30d35cc341e42f0dc48148eb54e94fac8fb4/ros2.repos
BUILD args: --packages-above-and-dependencies rclcpp
TEST args: --packages-above rclcpp
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/20059

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@fujitatomoya fujitatomoya self-assigned this Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants