Skip to content
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

The SocketTransportDescriptor::min_send_buffer_size() method returns too large value when exceeded net.core.wmem_max #4684

Open
1 task done
i-and opened this issue Apr 14, 2024 · 1 comment
Labels
triage Issue pending classification

Comments

@i-and
Copy link

i-and commented Apr 14, 2024

Is there an already existing issue for this?

  • I have searched the existing issues

Expected behavior

The values sendBufferSize and receiveBufferSize from the SocketTransportDescriptor adequately reflect the buffer sizes of the created UDP sockets.

Current behavior

The values sendBufferSize and receiveBufferSize from the SocketTransportDescriptor and SocketTransportDescriptor::min_send_buffer_size() method return larger values than the actual size of the UDP socket buffers.

Steps to reproduce

Using the fields sendBufferSize and receiveBufferSize from the SocketTransportDescriptor , you must set a value greater than net.core.wmem_max or net.core.rmem_max.

Fast DDS version/commit

v2.13.0

Platform/Architecture

Ubuntu Focal 20.04 amd64

Transport layer

UDPv4

Additional context

No response

XML configuration file

No response

Relevant log output

No response

Network traffic capture

No response

@i-and i-and added the triage Issue pending classification label Apr 14, 2024
@i-and
Copy link
Author

i-and commented Apr 14, 2024

Below is a possible patch.

diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp
index 820056e26..9e9b05ea3 100644
--- a/src/cpp/rtps/transport/UDPTransportInterface.cpp
+++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp
@@ -151,6 +151,53 @@ bool UDPTransportInterface::init(
             }
         }
     }
+     
+    // Checking the possibility of setting buffer sizes
+    if (mSendBufferSize != 0 || mReceiveBufferSize != 0)
+    {
+        ip::udp::socket socket(io_service_);
+        socket.open(generate_protocol());
+
+        if (mSendBufferSize != 0)
+        {
+            assert(configuration()->sendBufferSize == mSendBufferSize);
+            socket.set_option(socket_base::send_buffer_size(static_cast<int32_t>(mSendBufferSize)));
+            socket_base::send_buffer_size option;
+            socket.get_option(option);
+            uint32_t real_size = static_cast<uint32_t>(option.value());
+            if (real_size != mSendBufferSize) {
+                EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "sendBufferSize=" << mSendBufferSize <<
+                    " cannot be set (max=" << real_size << ")");
+                set_send_buffer_size(real_size);
+                mSendBufferSize = real_size;
+                // NOTE: I suggest that we consider returning false here (i.e. initialization error). 
+                // This will change the behavior (it was not an error before), on the other hand, 
+                // it will draw the user's attention to the inability to set the specified buffer size 
+                // due to exceeding net.core.wmem_max.
+                // ??? return false; ???
+            }
+        }
+
+        if (mReceiveBufferSize != 0)
+        {
+            assert(configuration()->receiveBufferSize == mReceiveBufferSize);
+            socket.set_option(socket_base::receive_buffer_size(static_cast<int32_t>(mReceiveBufferSize)));
+            socket_base::receive_buffer_size option;
+            socket.get_option(option);
+            uint32_t real_size = static_cast<uint32_t>(option.value());
+            if (real_size != mReceiveBufferSize) {
+                EPROSIMA_LOG_ERROR(RTPS_MSG_OUT, "receiveBufferSize=" << mReceiveBufferSize <<
+                    " cannot be set (max=" << real_size << ")");
+                set_receive_buffer_size(real_size);
+                mReceiveBufferSize = real_size;
+                // NOTE: I suggest that we consider returning false here (i.e. initialization error). 
+                // This will change the behavior (it was not an error before), on the other hand, 
+                // it will draw the user's attention to the inability to set the specified buffer size 
+                // due to exceeding net.core.rmem_max.
+                // ??? return false; ???
+            }
+        }
+    }
 
     if (configuration()->maxMessageSize > s_maximumMessageSize)
     {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Issue pending classification
Projects
None yet
Development

No branches or pull requests

1 participant