eProsima / Fast-DDS

The most complete DDS - Proven: Plenty of success cases. Looking for commercial support? Contact info@eprosima.com
https://eprosima.com
Apache License 2.0
2.04k stars 730 forks source link

Error sending the sample when using XCDR2 #4942

Open i-and opened 3 weeks ago

i-and commented 3 weeks ago

Is there an already existing issue for this?

Expected behavior

The sample is successfully sent regardless of its size.

Current behavior

Depending on the size of the sample, the write() method returns an error code.

Steps to reproduce

This error can be reproduced by modifying HelloWorldExample as follows:

diff --git a/examples/cpp/dds/HelloWorldExample/HelloWorldPublisher.cpp b/examples/cpp/dds/HelloWorldExample/HelloWorldPublisher.cpp
index 86f3e0009..aeaa239d6 100644
--- a/examples/cpp/dds/HelloWorldExample/HelloWorldPublisher.cpp
+++ b/examples/cpp/dds/HelloWorldExample/HelloWorldPublisher.cpp
@@ -43,7 +43,7 @@ bool HelloWorldPublisher::init(
         bool use_env)
 {
     hello_.index(0);
-    hello_.message("HelloWorld");
+    hello_.message().resize(256, 'A');
     DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
     pqos.name("Participant_pub");
     auto factory = DomainParticipantFactory::get_instance();
@@ -106,6 +106,7 @@ bool HelloWorldPublisher::init(
     {
         publisher_->get_default_datawriter_qos(wqos);
     }
+    wqos.representation().m_value.push_back(XCDR2_DATA_REPRESENTATION);

     writer_ = publisher_->create_datawriter(
         topic_,
@@ -218,7 +219,9 @@ bool HelloWorldPublisher::publish(
     if (listener_.firstConnected_ || !waitForListener || listener_.matched_ > 0)
     {
         hello_.index(hello_.index() + 1);
-        writer_->write(&hello_);
+        if (!writer_->write(&hello_)) {
+            printf("ERROR WRITE SAMPLE!!!\n");
+        }
         return true;
     }
     return false;
diff --git a/examples/cpp/dds/HelloWorldExample/HelloWorldSubscriber.cpp b/examples/cpp/dds/HelloWorldExample/HelloWorldSubscriber.cpp
index 6823a32f4..145ba4d9f 100644
--- a/examples/cpp/dds/HelloWorldExample/HelloWorldSubscriber.cpp
+++ b/examples/cpp/dds/HelloWorldExample/HelloWorldSubscriber.cpp
@@ -106,6 +106,8 @@ bool HelloWorldSubscriber::init(
         subscriber_->get_default_datareader_qos(rqos);
     }

+    rqos.type_consistency().representation.m_value.push_back(XCDR2_DATA_REPRESENTATION);
+
     reader_ = subscriber_->create_datareader(topic_, rqos, &listener_);

     if (reader_ == nullptr)
diff --git a/examples/cpp/dds/HelloWorldExample/HelloWorld_main.cpp b/examples/cpp/dds/HelloWorldExample/HelloWorld_main.cpp
index 35870eb67..bcaebd3cd 100644
--- a/examples/cpp/dds/HelloWorldExample/HelloWorld_main.cpp
+++ b/examples/cpp/dds/HelloWorldExample/HelloWorld_main.cpp
@@ -291,6 +291,8 @@ int main(
         }
     }

+    Log::SetVerbosity(Log::Kind::Warning);
+
     switch (type)
     {
         case 1:

Fast DDS version/commit

v2.14.1

Platform/Architecture

Ubuntu Focal 20.04 amd64

Transport layer

Default configuration, UDPv4 & SHM

Additional context

No response

XML configuration file

No response

Relevant log output

2024-06-12 20:47:00.881 [DATA_WRITER Warning] Data serialization returned false -> Function perform_create_new_change
ERROR WRITE SAMPLE!!!
Message: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA with index: 4 SENT

Network traffic capture

No response

elianalf commented 2 weeks ago

Hi @i-and, Thank you for using Fast DDS.

There might be an issue with the data serialization in case the message size is greater than 255 and the extensibility of the message type defined in the .idl is APPENDABLE, which is by default. I will label it as bug. In the meanwhile, you can still accomplish what you are trying to do, setting the extensibility to FINAL in the HelloWorld.idl file as follow:

@final
struct HelloWorld
{
    unsigned long index;
    string message;
};

and regenerate the types with Fast DDS-GEN. If you haven't installed it yet, you can follow the installation instructions and then the usage guide to regenerate types adding the -replace argument.