test: shut rclcpp down after every lifecycle handler suite - #695
Merged
Merged
Conversation
test_lifecycle_handlers could segfault at exit with every test passed. Two of its three fixtures had an empty TearDownTestSuite, so the default context was still initialised when the process left main. rclcpp 28.1.22 shuts that context down from a static destructor inside exit(), which runs after the main thread's thread_local objects are destroyed, and Context::shutdown touches one of them. The crash needs an earlier main-thread shutdown to have created that object, and LifecycleHandlersTest does exactly that in its own teardown. Both fixtures now shut rclcpp down the same guarded way, so the context is already down when the static destructor runs.
bburda
marked this pull request as ready for review
September 20, 2026 16:05
mfaferek93
approved these changes
Sep 20, 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.
Summary
test_lifecycle_handlerscould exit with SIGSEGV after every test passed. Two of its three fixtures had an emptyTearDownTestSuite, so the default context was still initialised when the process leftmain. rclcpp 28.1.22 shuts that context down from a static destructor insideexit(), which runs after the main thread'sthread_localobjects are destroyed, andContext::shutdowntouches one of them. The crash needs an earlier main-thread shutdown to have created that object, andLifecycleHandlersTestdoes that in its own teardown.Both fixtures now shut rclcpp down the same guarded way as the first one. Every
SetUpTestSuitein the file already guards onrclcpp::ok(), so a later suite re-initialises safely.Ten other test sources call
rclcpp::initand neverrclcpp::shutdown. None of them shuts a context down on the main thread, and a program that only initialises never crashes this way, so they are left as they are.Issue
Type
Testing
In a container on
ros:jazzy-ros-base(rclcpp 28.1.22; the development machine has 28.1.21, where the crash cannot happen), running the real binary with one test per fixture so the exit shape is kept:Four minimal rclcpp programs, 50 runs each, show the shape: init only and init plus shutdown are clean, init plus shutdown plus init segfaults in 10 of 50, and init plus shutdown plus init plus shutdown is clean. The backtrace is
Context::shutdownunder~Contextunder__run_exit_handlers.colcon test --packages-select ros2_medkit_gateway: 4306 tests, 0 failures.Checklist