ros2 / ros2/rclcpp

ParameterClient request is not finished although executor is canceled.

Open
#1,022 0 comments 0 reactions 1 assignee View on GitHub

@wjwwood is already working on this.

Since Mar 26, 2020.

Dominant language
C++
Stars
805
Forks
564
Avg merge
1d 17h
Merged PRs (30d)
27

Description

Bug report

Required Info:

  • Operating System:
    • Ubuntu 18.04
  • Installation type:
    • from source
  • Version or commit hash:
    • dashing, master
  • DDS implementation:
    • Fast-RTPS
  • Client library (if applicable):
    • rclcpp
Steps to reproduce issue

Parameter Server code

#include <chrono>
#include <iostream>
#include <memory>
#include <vector>

#include <rclcpp/rclcpp.hpp>

int main(int argc, char *argv[]) {
  rclcpp::init(argc, argv);

  rclcpp::executors::SingleThreadedExecutor executor;
  auto node = std::make_shared<rclcpp::Node>("param_test_server_node");
  auto test_param = "test_param";

  rcl_interfaces::msg::ParameterDescriptor descriptor;
  descriptor.read_only = false;
  node->declare_parameter(test_param, rclcpp::ParameterValue(10), descriptor);

  executor.add_node(node);

  node->set_on_parameters_set_callback([&](const std::vector<rclcpp::Parameter> & parameters) {
        rcl_interfaces::msg::SetParametersResult result;
        std::cout << "set_parameter callback is called" << std::endl;
        result.successful = true;
        for (const auto & parameter : parameters) {
          if (parameter.get_name() == test_param)
          {
            std::cout << test_param << " " << parameter.value_to_string() << std::endl;
          }
        }
        std::this_thread::sleep_for(std::chrono::seconds(100));   // To reproduce the issue
        return result;
      });

  executor.spin();

  rclcpp::shutdown();

  return 0;
}

Parameter Client code

#include <chrono>
#include <iostream>
#include <memory>
#include <vector>

#include <rclcpp/rclcpp.hpp>

int main(int argc, char *argv[]) {
  rclcpp::init(argc, argv);

  auto remote_node = "/param_test_server_node";
  auto test_param = "test_param";

  auto exec = std::make_shared<rclcpp::executors::SingleThreadedExecutor>() ;
  auto node = std::make_shared<rclcpp::Node>("param_test_client");

  std::this_thread::sleep_for(std::chrono::seconds(1));

  auto parameters_client =
      std::make_shared<rclcpp::SyncParametersClient>(exec, node, remote_node);

  while (!parameters_client->wait_for_service(std::chrono::seconds(1))) {
    if (!rclcpp::ok()) {
      RCLCPP_ERROR(node->get_logger(), "interrupted, exit!");
      rclcpp::shutdown();
      return 0;
    }
    RCLCPP_INFO(node->get_logger(), "wait for service");
  }

  auto timer_callback = [&]() -> void {
      RCLCPP_INFO(node->get_logger(), "Timer expired");
      exec->cancel();
    };
  auto timer = node->create_wall_timer(std::chrono::seconds(5), timer_callback);

  std::vector<rclcpp::Parameter> set_params;
  set_params.emplace_back(test_param, 50);
  auto results = parameters_client->set_parameters(set_params);
  for (auto &result : results)
    RCLCPP_INFO(node->get_logger(), "result: %d", result.successful);
  RCLCPP_INFO(node->get_logger(), "done");
  timer->cancel();

  rclcpp::shutdown();

  return 0;
}

Expected behavior

Although set_parameters is not finished successfully, if executor is canceled then set_parameters must be finished.

set_parameter callback is called
test_param 50
[INFO] [1583914754.708738050] [param_test_client]: Timer expired
[INFO] [1583914754.709483787] [param_test_client]: done
Actual behavior

set_parameters does not finished although executor is cancled.

set_parameter callback is called
test_param 50
[INFO] [1583914837.349401253] [param_test_client]: Timer expired
[INFO] [1583914842.349311295] [param_test_client]: Timer expired

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.