From 5dcd5a39a428eee0f29b48f95fce86b150043270 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 08:23:43 -0700 Subject: [PATCH] Do not crash Executor when send_response fails due to client failure. (#2276) (#2279) * Do not crash Executor when send_response fails due to client failure. Related to https://github.com/ros2/ros2/issues/1253 It is not sane that a faulty client can crash our service Executor, as discussed in the referred issue, if the client is not setup properly, send_response may return RCL_RET_TIMEOUT, we should not throw an error in this case. Signed-off-by: Zang MingJie * Update rclcpp/include/rclcpp/service.hpp Co-authored-by: Tomoya Fujita Signed-off-by: Zang MingJie * address review comments. Signed-off-by: Tomoya Fujita --------- Signed-off-by: Zang MingJie Signed-off-by: Tomoya Fujita Co-authored-by: Zang MingJie (cherry picked from commit fbe8f28cd13710c5c643a4e7149e509f3a952677) Co-authored-by: Tomoya Fujita --- rclcpp/include/rclcpp/service.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rclcpp/include/rclcpp/service.hpp b/rclcpp/include/rclcpp/service.hpp index 3cfc11e9ca..af00241c31 100644 --- a/rclcpp/include/rclcpp/service.hpp +++ b/rclcpp/include/rclcpp/service.hpp @@ -482,6 +482,14 @@ class Service { rcl_ret_t ret = rcl_send_response(get_service_handle().get(), &req_id, &response); + if (ret == RCL_RET_TIMEOUT) { + RCLCPP_WARN( + node_logger_.get_child("rclcpp"), + "failed to send response to %s (timeout): %s", + this->get_service_name(), rcl_get_error_string().str); + rcl_reset_error(); + return; + } if (ret != RCL_RET_OK) { rclcpp::exceptions::throw_from_rcl_error(ret, "failed to send response"); }