From e888840de9b41e072e928e84b5dd5572fef28e2a Mon Sep 17 00:00:00 2001 From: Tomoya Fujita Date: Mon, 11 Sep 2023 13:34:07 -0700 Subject: [PATCH] Decouple rosout publisher fini from node fini. Signed-off-by: Tomoya Fujita --- rclcpp/src/rclcpp/node_interfaces/node_base.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/rclcpp/src/rclcpp/node_interfaces/node_base.cpp b/rclcpp/src/rclcpp/node_interfaces/node_base.cpp index 12cda87974..81a5bdead1 100644 --- a/rclcpp/src/rclcpp/node_interfaces/node_base.cpp +++ b/rclcpp/src/rclcpp/node_interfaces/node_base.cpp @@ -129,10 +129,17 @@ NodeBase::NodeBase( node_handle_.reset( rcl_node.release(), [logging_mutex](rcl_node_t * node) -> void { - std::lock_guard guard(*logging_mutex); - // TODO(ivanpauno): Instead of mutually excluding rcl_node_fini with the global logger mutex, - // rcl_logging_rosout_fini_publisher_for_node could be decoupled from there and be called - // here directly. + { + std::lock_guard guard(*logging_mutex); + if (rcl_logging_rosout_enabled()) { + rcl_ret_t ret = rcl_logging_rosout_fini_publisher_for_node(node); + if (ret != RCL_RET_OK) { + RCUTILS_LOG_ERROR_NAMED( + "rclcpp", + "Error in destruction of rosout publisher: %s", rcl_get_error_string().str); + } + } + } if (rcl_node_fini(node) != RCL_RET_OK) { RCUTILS_LOG_ERROR_NAMED( "rclcpp",