From 3de75ebba527d34154a97e772c3742ae5d88c2e3 Mon Sep 17 00:00:00 2001 From: Bartosz Burda Date: Sun, 20 Sep 2026 17:58:04 +0200 Subject: [PATCH] test: shut rclcpp down after every lifecycle handler suite 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. --- src/ros2_medkit_gateway/test/test_lifecycle_handlers.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ros2_medkit_gateway/test/test_lifecycle_handlers.cpp b/src/ros2_medkit_gateway/test/test_lifecycle_handlers.cpp index 9cbea1b35..08e611979 100644 --- a/src/ros2_medkit_gateway/test/test_lifecycle_handlers.cpp +++ b/src/ros2_medkit_gateway/test/test_lifecycle_handlers.cpp @@ -329,6 +329,9 @@ class EntityDetailStatusLinkTest : public ::testing::Test { } static void TearDownTestSuite() { + if (rclcpp::ok()) { + rclcpp::shutdown(); + } } void SetUp() override { @@ -471,6 +474,9 @@ class LifecycleHandlersWithProviderTest : public ::testing::Test { } static void TearDownTestSuite() { + if (rclcpp::ok()) { + rclcpp::shutdown(); + } } void SetUp() override {