From d45b7ea12ea39dc02cd160ed923f21c5cf5c03a4 Mon Sep 17 00:00:00 2001 From: Mauro Passerino Date: Mon, 3 Oct 2022 12:13:18 +0100 Subject: [PATCH] Remove service entries if gone out of scope Signed-off-by: Mauro Passerino --- .../experimental/intra_process_manager.hpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/rclcpp/include/rclcpp/experimental/intra_process_manager.hpp b/rclcpp/include/rclcpp/experimental/intra_process_manager.hpp index e519adb409..7c48d914bf 100644 --- a/rclcpp/include/rclcpp/experimental/intra_process_manager.hpp +++ b/rclcpp/include/rclcpp/experimental/intra_process_manager.hpp @@ -304,9 +304,23 @@ class IntraProcessManager auto service_it = services_.find(service_id); if (service_it == services_.end()) { - throw std::runtime_error( - "There are no services to receive the intra-process request. " - "Do Inter process."); + auto cli = get_client_intra_process(intra_process_client_id); + auto warning_msg = + "Intra-process service gone out of scope. " + "Do inter-process requests.\n" + "Client topic name: " + std::string(cli->get_service_name()); + RCLCPP_WARN(rclcpp::get_logger("rclcpp"), warning_msg.c_str()); + + // Remove all entries of the out-of-scope service + // from the client/service pairs. + for (auto it = clients_to_services_.cbegin(); it != clients_to_services_.cend(); ) { + if (it->second == service_id) { + it = clients_to_services_.erase(it); + } else { + it++; + } + } + return; } auto service_intra_process_base = service_it->second.lock(); if (service_intra_process_base) {