Discovery race condition mitigation #174
@fujitatomoya Could you please run the CI for us? I don't have access to ROS 2 CI yet
Pulls: ros2/rmw_connextdds#174
Gist: https://gist.githubusercontent.com/fujitatomoya/840e409da057b6367478e772cd5ce83a/raw/d810da54ea2d027299836d08eceb8127dbc18e0e/ros2.repos
BUILD args: --packages-above-and-dependencies rmw_connextdds_common
TEST args: --packages-above rmw_connextdds_common
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15308
Linux 
Linux-aarch64 
Linux-rhel 
Windows 
instanceHandle should be instance_handle
should we file a bug about this issue to not lose track?
if (DDS_RETCODE_OK != DDS_DataWriter_get_qos(writer(), &dw_qos)) {
No need for this constant because its name is misleading. The constant is only used in load_max_blocking_time if there is an error getting the writer QoS (not expected) or when dw_qos.reliability.max_blocking_time is set to AUTO which is not allowed in Connext.
Remove this check.
dw_qos.reliability.max_blocking_time cannot have the AUTO value. The range is: [0,1 year] or DDS_DURATION_INFINITE
Remove the DDS_Duration_is_auto check
std::chrono::duration_cast<std::chrono::microseconds >
return std::chrono::microseconds(RMW_CONNEXT_LIMIT_DEFAULT_BLOCKING_TIME_INFINITE);
Rename unmatched with unknown. The unmatched term is misleading. See my previous function comment.
Add comment explaining the function
// Waits for the `RMW_Connext_Publisher`'s DataWriter to match a known
// DataReader with GID `reader_gid`.
//
// A DataReader is considered known if its GID is present in the
// `known_endpoints` map.
//
// If this API is called with a `reader_gid` that is not in `known_endpoints`,
// it returns `RMW_RET_OK` with `unknown` set to `true`.
//
// An `RMW_Connext_Service` (using Extended mapping) uses this API to wait for
// an `RMW_Connext_Client`'s DataReader, identified by `reader_gid`, to match
// its DataWriter.
//
// An `RMW_Connext_Service` adds a DataReader's GID to `known_endpoints` when
// it receives a request from its own DataReader.
Add comment
// This method is called by a RMW_Connext_Service when a RMW_Connext_Client's
// DataWriter is matched/unmatched with the Service's DataReader
Add comment
// Map of endpoints to related endpoints associated with a
// RMW_Connext_Publisher.
//
// In a RMW_Connext_Service's RMW_Connext_Publisher, this map
// contains two pairs for each matched RMW_Connext_Client:
// (RMW_Connext_Client's DataWriter, RMW_Connext_Client's DataReader)
// (RMW_Connext_Client's DataReader, RMW_Connext_Client's DataWriter)
Requested changes.
Add relevant comments
// This type is internal to the implementation and it is not sent over the wire
struct RMW_Connext_RequestReplyMessage
{
bool request;
// In basic mapping, this is the GID of the client's DataWriter
// In extended mapping, this is the GID of the client's DataReader
rmw_gid_t gid;
// This is the GID of the writer that sent the request
rmw_gid_t writer_gid;
int64_t sn;
void * payload;
};
Print an error message if the call to this function returns DDS_BOOLEAN_FALSE
Add comment
// For extended request reply mapping this is the Client's DataReader GUID
// which we are sending as part of the related_sample_identity
src_guid = &related_sample_identity->writer_guid;
We only want to run this method if we are dealing with a Service's DataWriter. Add this guard:
// This callback is only used by the RMW_Connext_Service's RMW_Connext_Publisher
if (this->type_support->message_type() != RMW_CONNEXT_MESSAGE_REPLY) {
return;
}
// This callback is only used by the RMW_Connext_Service's RMW_Connext_Publisher
if (this->type_support->message_type() != RMW_CONNEXT_MESSAGE_REPLY) {
return;
}
Requested changes.
Can you merge rolling into this branch. There have been a few changes in rmw_connext.cpp
Requested changes.
@fujitatomoya can you run the CI please? Hopefully the changes fix the instabilities.
Pulls: ros2/rmw_connextdds#174
Gist: https://gist.githubusercontent.com/fujitatomoya/10d8e9025b39088ef528d3b580f8d732/raw/d810da54ea2d027299836d08eceb8127dbc18e0e/ros2.repos
BUILD args: --packages-above-and-dependencies rmw_connextdds_common
TEST args: --packages-above rmw_connextdds_common
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15372
Linux 
Linux-aarch64 
Linux-rhel 
Windows 
No need to use `` in these comments
Consider changing this name to wait_for_client_subscription as the semantic is quiet specific to the Client/Service communication pattern. New prototype:
// When invoked in a Service's RMW_Connext_Publisher, this API waits for
// the RMW_Connext_Publisher's DataWriter to match the Client's DataReader.
// associated with the Client's DataWriter identified by `client_writer_gid`.
//
// If this API is not invoked in a Service's RMW_Connext_Publisher, it returns
// `RMW_RET_ERROR`.
//
// If the `client_writer_gid` is not in the `known_endpoints`, it returns
// `RMW_RET_OK` with `unknown` set to `true`.
//
// Known endpoints are added to the `known_endpoints` map when a Service's
// DataReader receives a request from a Client's DataWriter using the API
// push_related_endpoints
rmw_ret_t wait_for_client_subscription(rmw_gid_t &client_writer_gid, bool &unknown);
return an error in the RMW_Connext_Publisher is not a Service's RMW_Connext_Publisher
if (this->type_support->message_type() != RMW_CONNEXT_MESSAGE_REPLY) {
return RMW_RET_ERROR;
}
Requested changes.
I think the pull request is ready to be merged. @fujitatomoya can you run the CI for us?
@fgallegosalido, As long as the tests pass, I’m fine with merging this Pull Request.
Pulls: ros2/rmw_connextdds#174
Gist: https://gist.githubusercontent.com/fujitatomoya/ff8d937cddf769373fd038f434989f1d/raw/d810da54ea2d027299836d08eceb8127dbc18e0e/ros2.repos
BUILD args: --packages-above-and-dependencies rmw_connextdds_common
TEST args: --packages-above rmw_connextdds_common
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15409
Linux 
Linux-aarch64 
Linux-rhel 
Windows 
i think unknown need to be handled as warning case, because it is not expected to happen usually? returning success with unknown=true, it just looks like send_response successfully writes the message to the associated data reader from the caller. but that is not what happened here.
these changes aim to enhance the functionality and reliability of the RMW_Connext_Publisher (service server response sender) and RMW_Connext_Subscriber (service client response reader), particularly in managing endpoint relationships and synchronization for the service. IMO, this really makes sense and probably mitigate the racy condition to miss the response message between service server and clients.
just a minor comment that i would like to confirm.
@fujitatomoya
We have reviewed your comment and confirmed that maintaining compatibility with older clients or clients from other vendors could trigger getting “unknown” from wait_for_client_subscription.
To address this, we have modified the solution and added more comments to clarify the different situations that may occur. Additionally, we have included a warning message to notify the user. you can check the changes in this commit: https://github.com/ros2/rmw_connextdds/pull/174/commits/0e02fc576f4b0cb3a6df5bd722eca595e810a434
Thanks for flagging that! 🙂
@fujitatomoya
Could you help with another CI validation run? I have updated the branch to the latest rolling state since the last run failed due to a build issue with a package unrelated to rmw_connext.
Approved these changes.
Pulls: ros2/rmw_connextdds#174
Gist: https://gist.githubusercontent.com/fujitatomoya/dd2df341bc96e76e44327ba5ff3383f7/raw/d810da54ea2d027299836d08eceb8127dbc18e0e/ros2.repos
BUILD args: --packages-above-and-dependencies rmw_connextdds_common
TEST args: --packages-above rmw_connextdds_common
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15428
Linux 
Linux-aarch64 
Linux-rhel 
Windows 
@fujitatomoya
The Linux-rhel build has failed, but it appears to be unrelated to the changes in this PR. Are we allowed to merge it, or should we look into the issue more deeply?
In any case, I’ve also fixed the uncrustify formatting issues. Do we need to rerun the Linux and Windows builds now?
Lastly, thanks a lot for running the CI for us! Do you know who we should contact to get access to run the builds ourselves in the future?
@lobolanja i will restart the CI.
Pulls: ros2/rmw_connextdds#174
Gist: https://gist.githubusercontent.com/fujitatomoya/8b2451d6623cf8e4b9eb54091235e6d0/raw/d810da54ea2d027299836d08eceb8127dbc18e0e/ros2.repos
BUILD args: --packages-above-and-dependencies rmw_connextdds_common
TEST args: --packages-above rmw_connextdds_common
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15444
Linux 
Linux-aarch64 
Linux-rhel 
Windows 
Approved these changes.
@fujitatomoya the Windows build was aborted, but the test issues that affected previous builds seem to be finished as per the Linux build. Are we okay to merge?
@fgallegosalido test was aborted, so not completed. i just started the new CI for windows.
when this comes green, i believe that it is good to go.
@fujitatomoya a couple of tests failed in Windows, but they don't seem related to the changes in this pr. Is it okay to merge now?
windows warnings are unrelated and https://ci.ros2.org/job/ci_windows/23727/testReport/ros2bag.test/test_record_qos_profiles/test_record_qos_profiles/ has been addressed by https://github.com/ros2/rosbag2/pull/1949.
lobolanja
fgallegosalido
This yet another attempt at merging a mitigation for the discovery race condition. The first attempt happened in https://github.com/ros2/rmw_connextdds/pull/132. This pull request has the same fix plus a couple of fixes and improvements.