Skip to content

wait_for_message uses default ros context instead of passed node's context #3020

@rahatchd

Description

@rahatchd

Generated by Generative AI

No response

Operating System:

Ubuntu 24.04 (irrelevant)

ROS version or commit hash:

jazzy

RMW implementation (if applicable):

rmw_fastrtps_cpp

RMW Configuration (if applicable):

In wait_for_message.hpp, the wait set is default constructed so it uses the default global ros context. If an application is using a custom context and wants to use wait_for_message it can't. The global context must be initialized to use wait for message.

Client library (if applicable):

rclcpp

'ros2 doctor --report' output

ros2 doctor --report
<COPY OUTPUT HERE>

Steps to reproduce issue

  1. Create a rclcpp::Context and initialize it
  2. Create a node using that context
  3. Don't initialize the global context (ie don't call rclcpp::init)
  4. Call rclcpp::wait_for_message(msg, node, topic, timeout, qos)

Expected behavior

Topic is waited on.

Actual behavior

Segfault as wait_set's context (global default) is not initialized.

Failed to create wait set: context argument is null, at ./src/rcl/wait.c:128

Additional information

The GuardCondition already uses the node's context, but the wait set is default constructed. It should be

rclcpp::WaitSet wait_set({}, {}, {}, {}, {}, {}, context);

Metadata

Metadata

Assignees

No one assigned

    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