fix: prevent double-shutdown in rclcpp::Context - #3216
Closed
fishitiny wants to merge 1 commit into
Closed
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>
fishitiny
marked this pull request as draft
August 5, 2026 10:56
fishitiny
marked this pull request as ready for review
August 5, 2026 10:58
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
Collaborator
|
This is ABI breaking. Therefore it can not be merged into a stable distro. |
Collaborator
|
@fishitiny thanks for rasing the issue here, as @jmachowinski mentioned above, can you address this issue to our development branch which is rolling? besides, ABI breaking change is not allowed to downstream distribution. that said it will not be possible to backport the current fix to the humble. |
Collaborator
|
@fishitiny if you can take a look at #3217, thta would be appreciated. |
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
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:
GDB backtrace from core dump:
Thread 1: raise() -> abort()
-> rclcpp::Context::shutdown()
-> rclcpp::SignalHandler::deferred_signal_handler()
Is this user-facing behavior change?
Did you use Generative AI?
no