From 2846263f4174a7eafb1ef373af8a5432fca14976 Mon Sep 17 00:00:00 2001 From: MarqRazz Date: Mon, 9 Mar 2026 08:01:06 -0600 Subject: [PATCH] Fix race condition on shutdown in try_discover_source() Signed-off-by: MarqRazz --- topic_tools/src/tool_base_node.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/topic_tools/src/tool_base_node.cpp b/topic_tools/src/tool_base_node.cpp index 17987a1..5d52a11 100644 --- a/topic_tools/src/tool_base_node.cpp +++ b/topic_tools/src/tool_base_node.cpp @@ -103,6 +103,12 @@ void ToolBaseNode::make_subscribe_unsubscribe_decisions() std::optional> ToolBaseNode::try_discover_source() { + // Guard against calls that race with rclcpp::shutdown(): after the context is + // invalidated get_publishers_info_by_topic() will throw an RCLError. + if (!rclcpp::ok(this->get_node_base_interface()->get_context())) { + return {}; + } + // borrowed this from domain bridge // (https://github.com/ros2/domain_bridge/blob/main/src/domain_bridge/wait_for_graph_events.hpp) // Query QoS info for publishers