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