Skip to content

test: shut rclcpp down after every lifecycle handler suite - #695

Merged
bburda merged 1 commit into
mainfrom
fix/tests-shut-rclcpp-down
Sep 20, 2026
Merged

bburda merged 1 commit into
mainfrom
fix/tests-shut-rclcpp-down

Conversation

@bburda

@bburda bburda commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

test_lifecycle_handlers could exit with SIGSEGV after 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 that in its own teardown.

Both fixtures now shut rclcpp down the same guarded way as the first one. Every SetUpTestSuite in the file already guards on rclcpp::ok(), so a later suite re-initialises safely.

Ten other test sources call rclcpp::init and never rclcpp::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

  • none, test-only change

Type

  • Bug fix
  • New feature or tests
  • Breaking change
  • Documentation only

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:

  • before: 54 runs, 9 segfaults, each with all tests passed;
  • after: 200 runs, 0 segfaults, and 5 of 5 full runs of the unfiltered suite exit 0.

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::shutdown under ~Context under __run_exit_handlers.

colcon test --packages-select ros2_medkit_gateway: 4306 tests, 0 failures.


Checklist

  • Breaking changes are clearly described (and announced in docs / changelog if needed)
  • Tests were added or updated if needed
  • Docs were updated if behavior or public API changed

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
bburda marked this pull request as ready for review September 20, 2026 16:05
@bburda bburda self-assigned this Sep 20, 2026
@bburda
bburda merged commit 4addbda into main Sep 20, 2026
17 checks passed
@bburda
bburda deleted the fix/tests-shut-rclcpp-down branch September 20, 2026 17:44
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.

2 participants