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.16k stars 765 forks source link

DataWriter write data crash frequently with segment fault when using ContentFilteredTopic #4878

Closed GalaxyDreamWings closed 1 month ago

GalaxyDreamWings commented 4 months ago

Is there an already existing issue for this?

Expected behavior

use ContentFilteredTopic and set filter expression to receive required data

Current behavior

The operation seem to be valid and the application can run normally for a while but would crash occasionally or even frequently with segment fault. But if DataReader doesn't use ContentFilteredTopic, everything is well. The call stack is shown below:

libfastrtps. so. 2.14! void eprosima::fastdds::dds::ContentFilterInfo::cdr_serialize <eprosima: :fastdds: :dds: :ReaderFilterCollection: :update_filter_info (eprosima: :fastdds : :dds : :DataWriterFilteredChange&, eprosima::fastrtps: :rtps: :SampleIdentity const&) const:: {lambda (unsigned long,unsigned char)#1}>(eprosima: :fastrtps: :rtps: :SerializedPayload_t&, unsigned long, eprosima: :fastdds : : dds : :ReaderFilterCollection::update_filter_info (eprosima: :fastdds : :dds : :DataWriterFilteredChange&, eprosima::fastrtps::rtps: :SampleIdentity const&) const:: {lambda(unsigned long,unsigned char)#1}) (Unknown Source:0) libfastrtps. so. 2.14! eprosima::fastdds : : dds : :DataWriterImpl : :perforn_create_new_change (eprosima: :fastrtps::rtps::ChangeKind_t, void, eprosima::fastrtps: :rtps : :WriteParams&, eprosima: :fastrtps: :rtps : : InstanceHandle_t const&) (Unknown Source:0) libfastrtps.so. 2.14! eprosima::fastdds: :dds: :DataWriterImpl: :create_new_change_with_params (eprosima: :fastrtps: :rtps::ChangeKind_t, void, eprosima::fastrtps::rtps::WriteParams&) (Unknown Source:0) libfastrtps. so. 2. 14! eprosima: :fastdds : :dds : :DataWriterImpl : :create_new_change (eprosima::fastrtps: :rtps::ChangeKind_t, void) (Unknown Source:0) libfastrtps. so. 2. 14! eprosima: :fastdds: :dds : :DataWriterImpl: :write(void)(Unknown Source:0)

Steps to reproduce

The IDL file:

struct DMsg
{
    unsigned long actorId;
    sequence<char> msgContent;
};

And the filter expression:

string expression = "actorId = 0x12345678";
vector<string> parameters;
setTopicFilter(ESMsgId::eServerState,expression,parameters);

void CFastDDSManager::setTopicFilter(ESMsgId smsgId, std::string expression, std::vector<std::string> parameters)
{
    auto iter_map_topic = m_map_topic.find(smsgId);
    if (iter_map_topic != m_map_topic.end()) {
        if(iter_map_topic->second.pFilteredTopic == nullptr) {
            ContentFilteredTopic* pFilteredTopic = m_pParticipant->create_contentfilteredtopic(
                    iter_map_topic->second.pTopic->get_name() + "_Filtered", iter_map_topic->second.pTopic, expression,
                    parameters);

            iter_map_topic->second.pFilteredTopic = pFilteredTopic;
        }else {
            iter_map_topic->second.pFilteredTopic->set_filter_expression(expression,parameters);
        }
    }
}

relevant code for write data:

if(msg.getLength() != 0) {
        std::vector<char> vec_msgContent(msg.getContent(),msg.getContent() + msg.getLength());
        DMsg dmsg;
        dmsg.msgContent(vec_msgContent);
        dmsg.actorId(0x12345678);
        return iter_map_topic->second.writer->write(&dmsg);
}

Fast DDS version/commit

2.14.x

commit 74b2a74ef339816b6fef448efa676042a339b2e3 (HEAD -> master, origin/master, origin/HEAD, origin/2.14.x) Author: Des glaneurs 146199020+Desglaneurs@users.noreply.github.com Date: Tue Mar 12 17:34:01 2024 +0900

Platform/Architecture

Ubuntu Focal 20.04 arm64, Other. Please specify in Additional context section.

Transport layer

Default configuration, UDPv4 & SHM

Additional context

Galaxy Kylin OS (Linux) aarch64 run in docker

XML configuration file

No response

Relevant log output

No response

Network traffic capture

No response

elianalf commented 4 months ago

Hi @GalaxyDreamWings, thanks for using Fast DDS.

We will have a look and try to reproduce the issue. We will come back with a feedback.

Mario-DL commented 3 months ago

Hi @GalaxyDreamWings I have been testing with the following diff using a modified version of the ContentFilterTopicExample with the information you provided but I could not reproduce the issue. With that patch applied I tried DDSContentFilteredTopicExample --publisher in one terminal and DDSContentFilteredTopicExample --subscriber in another, then killing and relaunching the publisher several times, but no crash occurred.

I'm afraid that we would need more information about the application or a reproducer from your side, would it be possible ?

GalaxyDreamWings commented 3 months ago

Hi!@Mario-DL Thanks for your reply! But I'm sorry that I can't put my code here for some reason. I run my application in docker container on aarch64 server, so have you tried it? And It is confusing that it won't always crash, instead, it will run normally for a while , and crash occasionally. Also, the coredump trace always stop at eprosima::fastdds::dds::ContentFilterInfo::cdr_serialize function, but the data to be written seems normal. So can you find some clues for the problem with the coredump info that I provided? I can't solve it so I have to turn to try PartitionQos to achieve filter functionality. Hopes for your reply!

Mario-DL commented 1 month ago

Hi @GalaxyDreamWings,

Sorry for the delay in the response. Im afraid that we would need at least a simple reproducer to double check this. A hard guess would be that we are exceeding the num_filters, or not enough space in the SerializedPayload_t. In addition the platform goes out of the scope of supported platforms. I am moving this ticket to the appropriate forum.