Skip to content

Process crashes when constructing an action_server from a sub_node #1798

@yamokosk

Description

@yamokosk

Bug report

  • Operating System: Ubuntu 20.04.3 LTS
  • Installation type: binaries
  • Version or commit hash: foxy
  • DDS implementation: default
  • Client library (if applicable): rclcpp

Steps to reproduce issue

I've attached a zip file that contains a full project to demonstrate the issue. Here's the synopsis. When I create an action server with a rclcpp::Node object that is created from create_sub_node, the process crashes. Comment out the #define WORKS_FINE to reproduce.

#define WORKS_FINE

struct Foo
{
    using Fibonacci = action_tutorials_interfaces::action::Fibonacci;
    using GoalHandleFibonacci = rclcpp_action::ServerGoalHandle<Fibonacci>;

    Foo(rclcpp::Node::SharedPtr parent_node)
    {
#ifdef WORKS_FINE
        (void) parent_node;
        _node = rclcpp::Node::make_shared("foo");
#else
        _node = parent_node->create_sub_node("foo");
#endif
        _action_server = rclcpp_action::create_server<Fibonacci>(
            _node,
            "fibonacci",
            std::bind(&Foo::handle_goal, this, std::placeholders::_1, std::placeholders::_2),
            std::bind(&Foo::handle_cancel, this, std::placeholders::_1),
            std::bind(&Foo::handle_accepted, this, std::placeholders::_1));
    };

    rclcpp_action::GoalResponse handle_goal(const rclcpp_action::GoalUUID & uuid, std::shared_ptr<const Fibonacci::Goal> goal)
    {
        (void) uuid;
        (void) goal;
        return rclcpp_action::GoalResponse::REJECT;
    }

    rclcpp_action::CancelResponse handle_cancel(const std::shared_ptr<GoalHandleFibonacci> goal_handle)
    {
        (void) goal_handle;
        return rclcpp_action::CancelResponse::REJECT;
    }

    void handle_accepted(const std::shared_ptr<GoalHandleFibonacci> goal_handle)
    {
        (void) goal_handle;
    }

    rclcpp::Node::SharedPtr _node;
    rclcpp_action::Server<Fibonacci>::SharedPtr _action_server;
};

struct Bar
{
    Bar()
    {
        _node = rclcpp::Node::make_shared("bar");
        _foo = std::make_unique<Foo>(_node);
    };

    rclcpp::Node::SharedPtr _node;
    std::unique_ptr<Foo> _foo;
};

Expected behavior

Same behavior whether using a rclcpp::Node created from make_shared or create_sub_node.

Actual behavior

When constructing the action server from a node created from make_shared, the process runs normally.

When constructing the action server from the node created from create_sub_node:

# ros2 launch construct_action_server foobar_launch.py 
[INFO] [launch]: All log files can be found below /root/.ros/log/2021-10-11-20-27-30-521763-bbdd3c2e77a7-5122
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [foobar-1]: process started with pid [5124]
[ERROR] [foobar-1]: process has died [pid 5124, exit code -11, cmd '/root/install/construct_action_server/lib/construct_action_server/foobar --ros-args -r __ns:=/'].

Additional info

construct_action_server.zip

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions