-
Notifications
You must be signed in to change notification settings - Fork 266
Fix liveliness BEST_AVAILABLE handling in rclpy #1561
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
base: rolling
Are you sure you want to change the base?
Conversation
…ing to AUTOMATIC The Python QoS API exposes , but the underlying rmw layer does not define or support a “best available” liveliness enum value. As a result, rclpy forwarded the raw enum value (5) into rmw_qos_profile_t, leading to inconsistent behavior: - reports liveliness as AUTOMATIC - rclpy_qos_check_compatible reports LIVELINESS incompatibility - publisher and subscription using identical QoS settings cannot communicate This patch resolves the inconsistency by explicitly mapping to when building the rmw QoS profile. This matches how the best_available preset QoS profile is defined in rmw, and restores compatibility between endpoints. A deprecation warning may be added in a future release to clarify that BEST_AVAILABLE for liveliness is not a standalone rmw policy. Fixes: ros2/ros2#1722 Signed-off-by: pavansai018 <[email protected]>
ac7fb7c to
d9b6704
Compare
rmw layer does not define or support a “best available” liveliness enum value. As a result, rclpy forwarded the raw enum value (5) into rmw_qos_profile_t, leading to inconsistent behavior: - reports liveliness as AUTOMATIC - rclpy_qos_check_compatible reports LIVELINESS incompatibility - publisher and subscription using identical QoS settings cannot communicate This patch resolves the inconsistency by explicitly mapping to when building the rmw QoS profile. This matches how the best_available preset QoS profile is defined in rmw, and restores compatibility between endpoints. A deprecation warning may be added in a future release to clarify that BEST_AVAILABLE for liveliness is not a standalone rmw policy. Fixes: ros2/ros2#1722 Signed-off-by: pavansai018 <[email protected]>
rmw layer does not define or support a “best available” liveliness enum value. As a result, rclpy forwarded the raw enum value (5) into rmw_qos_profile_t, leading to inconsistent behavior: - reports liveliness as AUTOMATIC - rclpy_qos_check_compatible reports LIVELINESS incompatibility - publisher and subscription using identical QoS settings cannot communicate This patch resolves the inconsistency by explicitly mapping to when building the rmw QoS profile. This matches how the best_available preset QoS profile is defined in rmw, and restores compatibility between endpoints. A deprecation warning may be added in a future release to clarify that BEST_AVAILABLE for liveliness is not a standalone rmw policy. Fixes: ros2/ros2#1722 Signed-off-by: pavansai018 <[email protected]>
| # Resolve BEST_AVAILABLE liveliness before passing it to rmw. | ||
| liveliness = self.liveliness | ||
| if liveliness == QoSLivelinessPolicy.BEST_AVAILABLE: | ||
| # Map BEST_AVAILABLE to AUTOMATIC for rmw, since rmw doesn't define a | ||
| # separate BEST_AVAILABLE liveliness policy. | ||
| liveliness = QoSLivelinessPolicy.AUTOMATIC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i do not think this fixes the ros2/ros2#1722, because rmw_dds_common already does this. (the same process is done for publisher as well.)
@pavansai018 can you reproduce the issue ros2/ros2#1722 on jazzy distro? that i cannot reproduce it with the following.
root@tomoyafujita:/# ros2 topic pub --qos-depth 10 --qos-liveliness best_available /chatter std_msgs/msg/String "{data: \"Hello from command line\"}"
publisher: beginning loop
publishing #1: std_msgs.msg.String(data='Hello from command line')
publishing #2: std_msgs.msg.String(data='Hello from command line')
publishing #3: std_msgs.msg.String(data='Hello from command line')
publishing #4: std_msgs.msg.String(data='Hello from command line')
publishing #5: std_msgs.msg.String(data='Hello from command line')
...
root@tomoyafujita:/# ros2 topic echo --qos-depth 10 --qos-liveliness best_available /chatter
data: Hello from command line
---
data: Hello from command line
---
data: Hello from command line
---
data: Hello from command line
---
root@tomoyafujita:/# ros2 topic info /chatter -v
Type: std_msgs/msg/String
Publisher count: 1
Node name: _ros2cli_1177
Node namespace: /
Topic type: std_msgs/msg/String
Topic type hash: RIHS01_df668c740482bbd48fb39d76a70dfd4bd59db1288021743503259e948f6b1a18
Endpoint type: PUBLISHER
GID: 01.0f.76.65.99.04.46.41.00.00.00.00.00.00.07.03
QoS profile:
Reliability: RELIABLE
History (Depth): UNKNOWN
Durability: VOLATILE
Lifespan: Infinite
Deadline: Infinite
Liveliness: AUTOMATIC
Liveliness lease duration: Infinite
Subscription count: 1
Node name: _ros2cli_1192
Node namespace: /
Topic type: std_msgs/msg/String
Topic type hash: RIHS01_df668c740482bbd48fb39d76a70dfd4bd59db1288021743503259e948f6b1a18
Endpoint type: SUBSCRIPTION
GID: 01.0f.76.65.a8.04.20.ed.00.00.00.00.00.00.07.04
QoS profile:
Reliability: BEST_EFFORT
History (Depth): UNKNOWN
Durability: VOLATILE
Lifespan: Infinite
Deadline: Infinite
Liveliness: AUTOMATIC
Liveliness lease duration: InfiniteThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review. I have performed a clean test using the provided pub.py and sub.py files, both of which explicitly set the Liveliness QoS to LivelinessPolicy.BEST_AVAILABLE.
I can reproduce the error, and the log output below confirms a fatal QoS incompatibility on the LIVELINESS policy.
Reproduction Logs
The following logs confirm that communication fails immediately due to a QoS mismatch between the publisher and the subscriber:
Publisher Log:
The publisher detects the subscriber but warns that it cannot send data:

Subscriber Log:
The subscriber detects the publisher but warns that it cannot receive data:
![]()
Code Origin and Impact
The provided pub.py and sub.py files are heavily inspired by the official ROS 2 beginner tutorial code (https://docs.ros.org/en/jazzy/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Py-Publisher-And-Subscriber.html).
Note
I am using jazzy distro on Linux Mint (based on Ubuntu Noble)
But I am unable to reproduce same issue using ros2 topic pub --qos-depth 10 --qos-liveliness best_available /chatter std_msgs/msg/String "{data: \"Hello from command line\"}" and ros2 topic echo --qos-depth 10 --qos-liveliness best_available /chatter. Everything seems fine here. But rclpy is having an issue I guess.
Please let me know if you need any additional information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem is in rmw layer, so probably client interfaces are not related to this problem. i can reproduce the issue with samples with rolling, only with rmw_fastrtps_cpp.
rmw_cyclonedds_cpp,rmw_connextddsandrmw_zenoh_cppdoes not have this problem. (the following is the example output from rmw_cyclonedds_cpp)
$ RMW_IMPLEMENTATION=rmw_cyclonedds_cpp ros2 run prover_rclpy ros2_1722_pub
...
$ RMW_IMPLEMENTATION=rmw_cyclonedds_cpp ros2 run prover_rclpy ros2_1722_sub
...
$ RMW_IMPLEMENTATION=rmw_cyclonedds_cpp ros2 topic info -v /topic
Type: std_msgs/msg/String
Publisher count: 1
Node name: minimal_publisher
Node namespace: /
Topic type: std_msgs/msg/String
Topic type hash: RIHS01_df668c740482bbd48fb39d76a70dfd4bd59db1288021743503259e948f6b1a18
Endpoint type: PUBLISHER
GID: 01.10.12.d1.01.99.9d.bd.f6.c7.f7.20.00.00.16.03
QoS profile:
Reliability: RELIABLE
History (Depth): KEEP_LAST (10)
Durability: VOLATILE
Lifespan: Infinite
Deadline: Infinite
Liveliness: AUTOMATIC
Liveliness lease duration: Infinite
Subscription count: 1
Node name: minimal_subscriber
Node namespace: /
Topic type: std_msgs/msg/String
Topic type hash: RIHS01_df668c740482bbd48fb39d76a70dfd4bd59db1288021743503259e948f6b1a18
Endpoint type: SUBSCRIPTION
GID: 01.10.b8.52.54.3f.20.b0.d8.6d.19.37.00.00.16.04
QoS profile:
Reliability: RELIABLE
History (Depth): KEEP_LAST (10)
Durability: VOLATILE
Lifespan: Infinite
Deadline: Infinite
Liveliness: AUTOMATIC
Liveliness lease duration: InfiniteThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with rmw_fastrtps, we can see that liveliness policy falls to MANUAL_BY_TOPIC.
```console
$ ros2 topic info -v /topic
Type: std_msgs/msg/String
Publisher count: 1
Node name: minimal_publisher
Node namespace: /
Topic type: std_msgs/msg/String
Topic type hash: RIHS01_df668c740482bbd48fb39d76a70dfd4bd59db1288021743503259e948f6b1a18
Endpoint type: PUBLISHER
GID: 01.0f.9c.7b.4c.05.68.7f.00.00.00.00.00.00.13.03
QoS profile:
Reliability: RELIABLE
History (Depth): KEEP_LAST (10)
Durability: VOLATILE
Lifespan: Infinite
Deadline: Infinite
Liveliness: AUTOMATIC
Liveliness lease duration: Infinite
Subscription count: 1
Node name: minimal_subscriber
Node namespace: /
Topic type: std_msgs/msg/String
Topic type hash: RIHS01_df668c740482bbd48fb39d76a70dfd4bd59db1288021743503259e948f6b1a18
Endpoint type: SUBSCRIPTION
GID: 01.0f.9c.7b.61.05.71.92.00.00.00.00.00.00.13.04
QoS profile:
Reliability: RELIABLE
History (Depth): KEEP_LAST (10)
Durability: VOLATILE
Lifespan: Infinite
Deadline: Infinite
Liveliness: MANUAL_BY_TOPIC
Liveliness lease duration: InfiniteThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.


Fix liveliness BEST_AVAILABLE handling in rclpy
Summary
This PR resolves an inconsistency in how
rclpyhandlesLivelinessPolicy.BEST_AVAILABLE.The Python QoS API exposes this enum value, but the rmw layer does not implement a corresponding liveliness policy. As a result, rclpy forwarded an unsupported enum value into
rmw_qos_profile_t, causing incorrect introspection and QoS incompatibility warnings.This patch maps
LivelinessPolicy.BEST_AVAILABLEtoLivelinessPolicy.AUTOMATIC, aligning with how the rmw-definedqos_profile_best_availablebehaves.Problem
When both publisher and subscription use:
the following issues occur:
ros2 topic infoshowsAUTOMATICinstead of BEST_AVAILABLELIVELINESSincompatibilityRoot cause:
BEST_AVAILABLE(raw value5) is not a valid rmw liveliness policy and must be resolved to a supported value before constructing the rmw QoS profile.Solution
LivelinessPolicy.BEST_AVAILABLEin the QoSProfile setterLivelinessPolicy.AUTOMATICbefore sending it to rmwThis restores correct QoS negotiation and ensures consistent behavior across publisher/subscription endpoints.
Impact
Future Considerations
A future ROS 2 release may choose to deprecate liveliness BEST_AVAILABLE or extend rmw to support a formal best-available liveliness policy. This patch provides safe and deterministic behavior for current ROS 2 distributions.
Related Issue
Fixes: ros2/ros2#1722