Fast-RTPS is not gracefully closed on test exit

Hello!

In Fast-RTPS we have a new shared memory transport implementation, so we wanted to test its performance using this tool. To do that, we use a Fast-RTPS XML profile file to set the transport to shared memory (SHM), and then we load it setting environment variable FASTRTPS_DEFAULT_PROFILES_FILE. However, we have encountered that when using Fast-RTPS standalone on RELAY_MODE, the MAIN agent is not able to close when --max_runtime is reached.

We have narrowed it down to some threads not closing, preventing the application from closing down. This is because the test does not call any Fast-RTPS destructors, which prevents the SHM to release its resources. Note that when using ROS 2 stack, this problem does not arise, since the Node desctructor takes care of closing everything down.

The solution is simple, the test should call eprosima::fastrtps::Domain::stopAll() on closing. We have implemented so in main.cpp for quick testing, but since you have more insight in the application than we do, we think that instead of doing a MR, we'll let you decide where it suits best.

Quick patch

diff --git a/performance_test/src/main.cpp b/performance_test/src/main.cpp
index 62be5cf..45258d8 100644
--- a/performance_test/src/main.cpp
+++ b/performance_test/src/main.cpp
@@ -16,6 +16,10 @@
 
 #include "experiment_configuration/experiment_configuration.hpp"
 #include "experiment_execution/analyze_runner.hpp"
+#ifdef PERFORMANCE_TEST_FASTRTPS_ENABLED
+  #include <fastrtps/Domain.h>
+#endif
+
 
 int main(int argc, char ** argv)
 {
@@ -24,6 +28,14 @@ int main(int argc, char ** argv)
 
   rclcpp::init(argc, argv);
 
-  performance_test::AnalyzeRunner ar;
-  ar.run();
+  {
+    performance_test::AnalyzeRunner ar;
+    ar.run();
+  }
+#ifdef PERFORMANCE_TEST_FASTRTPS_ENABLED
+  if (ec.com_mean() == performance_test::CommunicationMean::FASTRTPS)
+  {
+    eprosima::fastrtps::Domain::stopAll();
+  }
+#endif
 }

Reproduce

To reproduce the issue, we are using ROS 2 Foxy, and Fast-RTPS eaddd8e49. We are also using the fix for RELAY_MODE for standalone Fast-RTPS proposed in !152 (merged). We run the following command:

export FASTRTPS_DEFAULT_PROFILES_FILE=~/ros2_apex_performance/shm.xml
ros2 run performance_test perf_test -t Array2m -c FastRTPS --max_runtime 5 --roundtrip_mode Main &
ros2 run performance_test perf_test -t Array2m -c FastRTPS --max_runtime 5 --roundtrip_mode Relay
XML file
<?xml version="1.0" encoding="UTF-8"?>
<dds xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
  <profiles>
    <transport_descriptors>
      <transport_descriptor>
        <transport_id>shm_transport</transport_id>
	<type>SHM</type>
      </transport_descriptor>
    </transport_descriptors>

    <participant profile_name="participant profile" is_default_profile="true">
      <rtps>
        <userTransports>
          <transport_id>shm_transport</transport_id>
        </userTransports>
        <useBuiltinTransports>false</useBuiltinTransports>
      </rtps>
    </participant>
  </profiles>
</dds>
Edited Mar 31, 2020 by Eduardo Ponz
Assignee Loading
Time tracking Loading