diff --git a/rclcpp/include/rclcpp/client.hpp b/rclcpp/include/rclcpp/client.hpp index 0816a2d..1637b83 100644 --- a/rclcpp/include/rclcpp/client.hpp +++ b/rclcpp/include/rclcpp/client.hpp @@ -197,7 +197,7 @@ public: std::shared_ptr request_header, std::shared_ptr response) { - std::lock_guard lock(pending_requests_mutex_); + std::unique_lock lock(pending_requests_mutex_); auto typed_response = std::static_pointer_cast(response); int64_t sequence_number = request_header->sequence_number; // TODO(esteve) this should throw instead since it is not expected to happen in the first place @@ -210,6 +210,9 @@ public: auto callback = std::get<1>(tuple); auto future = std::get<2>(tuple); this->pending_requests_.erase(sequence_number); + // Unlock here to allow the service to be called recursively from one of its callbacks. + lock.unlock(); + call_promise->set_value(typed_response); callback(future); }