fix: prevent double-shutdown in rclcpp::Context - #3220
Open
fujitatomoya wants to merge 2 commits into
Open
Conversation
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>
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
fujitatomoya
commented
Aug 11, 2026
fujitatomoya
left a comment
Collaborator
Author
There was a problem hiding this comment.
this is ABI breaking change, we will not backport this to downstream.
for backports, we will use #3219
Collaborator
Author
|
Pulls: #3220 |
skyegalaxy
approved these changes
Aug 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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