rcl icon indicating copy to clipboard operation
rcl copied to clipboard

RCL overwriting error state after rmw_create_node

Open allsey87 opened this issue 3 years ago • 2 comments

Bug report

Required Info:

  • Operating System: WebAssembly
  • Installation type: Source
  • Version or commit hash: Galactic
  • DDS implementation: Custom
  • Client library (if applicable): rclcpp

Expected behavior

RCL should fail gracefully when rmw_create_node returns NULL and sets the error state via RMW_SET_ERROR_MSG

Actual behavior

RCL ignores the fact the rmw_create_node set an error and returned NULL and then proceeds to overwrite the error state as follows:

failed to initialize rcl node: rcl node's rmw handle is invalid, at /home/developer/workspace/src/ros2/rcl/rcl/src/rcl/node.c:414
>>> [rcutils|error_handling.c:108] rcutils_set_error_state()
This error state is being overwritten:
'RMW_ERROR_MESSAGE, at RMW_FILENAME:0, at /home/developer/workspace/src/ros2/rcl/rcl/src/rcl/node.c:262'
with this new error message:
'rcl node's rmw handle is invalid, at /home/developer/workspace/src/ros2/rcl/rcl/src/rcl/node.c:414'
rcutils_reset_error() should be called after error handling to avoid this.
<<<

[ERROR] [0000000003.694284999] [rcl]: Failed to fini publisher for node: 1

allsey87 avatar May 13 '22 17:05 allsey87

i think this is bug.

https://github.com/ros2/rcl/blob/493ebf3a5d8fe2d861a93006a7d6908fd4e592d9/rcl/src/rcl/node.c#L251-L261

logger_name is assigned before rmw_create_node above. and if rmw_create_node fails, it goes to

https://github.com/ros2/rcl/blob/493ebf3a5d8fe2d861a93006a7d6908fd4e592d9/rcl/src/rcl/node.c#L305-L311

and call rcl_logging_rosout_fini_publisher_for_node w/o calling rcl_logging_rosout_init_publisher_for_node.

this leads to call rcl_node_is_valid_except_context to overwrite the error message.

fujitatomoya avatar May 16 '22 20:05 fujitatomoya

https://github.com/ros2/rcl/pull/985 can fix the problem, but according to https://github.com/ros2/rcl/pull/985#pullrequestreview-975525676, it would be nice to refactor the rcl_node_init and rcl_node_fini process to fix the complication and possible problem in the future.

fujitatomoya avatar May 17 '22 20:05 fujitatomoya