Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service request string type fails with microROS #775

Closed
hr-ti opened this issue Aug 26, 2024 · 2 comments
Closed

Service request string type fails with microROS #775

hr-ti opened this issue Aug 26, 2024 · 2 comments

Comments

@hr-ti
Copy link

hr-ti commented Aug 26, 2024

Bug report

Required Info:
I'm using microROS for my STM32 board and attempting to use services. The issue I'm getting on the MCU side is that deserializing the string type of a service request results in an error where the string length exceeds the capacity of the buffer, which is defaulting to 0 (erroring here).

I've verified that UDP traffic is working correctly. So I can only suspect that the host side is incorrectly converting service requests either in the RMW or the agent, not too sure how to confirm so input here would be great.

For my env, I use CycloneDDS and micro-ros-agent to handle bridging traffic between DDSes, but since the agent is built on top of FastDDS, service interoperability does not work directly. To workaround this, I send the raw data through a socket that pipes to a FastDDS node that communicates to the agent exclusively. This works perfectly for service requests that don't involve a string type in its request.

A good note to mention is that I've tried this in a rmw_fastrtps_cpp environment and the error persists, so it's not an interoperability issue.

Running my firmware through a debugger shows that it casts the appropriate service request typesupport onto the incoming ros_message once a service request is found, but capacity of the string type is always 0. Here's the generated typesupport code:

static bool _SetString_Request__cdr_deserialize(
  ucdrBuffer * cdr,
  void * untyped_ros_message)
{
  (void) cdr;

  bool rv = false;

  if (!untyped_ros_message) {
    return false;
  }
  _SetString_Request__ros_msg_type * ros_message = (_SetString_Request__ros_msg_type *)(untyped_ros_message);
  (void)ros_message;

  // Field name: data
  {
    size_t capacity = ros_message->data.capacity;
    uint32_t string_size;
    rv = ucdr_deserialize_sequence_char(cdr, ros_message->data.data, capacity, &string_size);
    if (rv) {
      ros_message->data.size = (string_size == 0) ? 0 : string_size - 1;
    } else if(string_size > capacity){
      cdr->error = false;
      cdr->last_data_size = 1;
      ros_message->data.size = 0;
      ucdr_align_to(cdr, sizeof(char));
      ucdr_advance_buffer(cdr, string_size);
    }
  }
  return rv;

My understanding could be wrong, but udr_deserialize_sequence_char uses ros_message->data.capacity to copy the appropriate amount of the input buffer cdr to ros_message. Here, ros_message->data.capacity is 0, udr_deserialize_sequence_char fails, rv is false and therefore causes an executor error.

Viewing the cdr buffer, I can see that the string I pass through is correct, including its length (+ null terminator), but ros_message attributes are incorrect.

I'm lost on where the buffer capacity property is set, but I'm hoping this is a user error and not an error from RMW.

  • Operating System:
    • Ubuntu 20.04
  • Installation type:
    • binary
  • Version or commit hash:
    • humble
  • DDS implementation:
    • FastDDS -> MicroXRCE-DDS
  • Client library (if applicable):
    • rclpy (host), rclc (MCU)

Steps to reproduce issue

  1. Make a service server on the MCU side, takes in a service request that has a string type
  2. Start micro-ros-agent and connect to MCU
  3. Call service from host

Expected behavior

The service server properly reads the request and handles appropriately

Actual behavior

Executor fails when deserializing the request

Additional information


Feature request

Feature description

Implementation considerations

@hr-ti
Copy link
Author

hr-ti commented Aug 26, 2024

After some testing, I realize this error persists when using a sequence or array of any type. Since capacity is always 0, only empty arrays work

@MiguelCompany
Copy link
Collaborator

@hr-ti I was going to tell you it was better to report this in any of the Micro-ROS repositories.

I see you already opened eProsima/Micro-XRCE-DDS#178, which has already been answered, so I am closing this one as duplicate.

@MiguelCompany MiguelCompany closed this as not planned Won't fix, can't repro, duplicate, stale Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants
@MiguelCompany @hr-ti and others