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

A reader receives RETCODE_NO_DATA with keyed topics when the value of the key is zero [12862] #2306

Closed
WataruToishita opened this issue Nov 5, 2021 · 9 comments · Fixed by #2316
Labels
bug Issue to report a bug

Comments

@WataruToishita
Copy link

A reader receives RETCODE_NO_DATA with keyed topics.

  1. Define a data type with a key like this:
    struct sample{
    octet index;
    @key octet key_value;
    };
  2. A writer write a sample with key_value = 0.
  3. A reader call take_next_sample() to get the sample, but it returns RETCODE_NO_DATA.

This symptom occurs only when key_value = 0.

Expected Behavior

A reader receives RETCODE_OK regardless of key_value.

Current Behavior

A reader receives RETCODE_NO_DATA only when key_value = 0.

Steps to Reproduce

  1. Edit this example and build.
    From my_sample.key_value(i + 1); to my_sample.key_value(i + 0);
  2. Run example (./Keys publisher)
  3. Run example (./Keys subscriber)
  4. Received samples with key_value!=0 will be printed in console.

System information

  • OS: Ubuntu 18.04.5
  • Fast-RTPS version:
    V2.4.0: This symptom occurs.
    V2.3.0: This symptom occurs.
    V2.2.0: No Problem
@MiguelCompany MiguelCompany changed the title A reader receives RETCODE_NO_DATA with keyed topics A reader receives RETCODE_NO_DATA with keyed topics when the value of the key is zero Nov 5, 2021
@MiguelCompany MiguelCompany added the bug Issue to report a bug label Nov 5, 2021
@MiguelCompany MiguelCompany changed the title A reader receives RETCODE_NO_DATA with keyed topics when the value of the key is zero A reader receives RETCODE_NO_DATA with keyed topics when the value of the key is zero [12862] Nov 5, 2021
@fujitatomoya
Copy link
Contributor

CC: @Barry-Xu-2018 @iuhilnehc-ynos (This problem is originally come from one of our division.)

@Barry-Xu-2018
Copy link
Contributor

After quickly checking, I found

While key_value is 0, an invalid InstanceHandle_t is created.

struct sample{
octet index;
@Key octet key_value;
};

While key_value is 0, the value of InstanceHandle_t is 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.

struct RTPS_DllAPI InstanceHandle_t
{
//!Value
octet value[16];

If each value is 0, it is considered to be undefined.

/**
* Know if the instance handle is defined
* @return True if the values are not zero.
*/
bool isDefined() const
{
for (uint8_t i = 0; i < 16; ++i)
{
if (value[i] != 0)
{
return true;
}
}
return false;
}

Get warning while creating new_change.

if (m_att.topicKind == WITH_KEY && !handle.isDefined())
{
logWarning(RTPS_WRITER, "Changes in KEYED Writers need a valid instanceHandle");
}

InstanceHandle_t is created by the below code, which is produced by fastcdrgen tool.
So need to consider this special case while creating InstanceHandle_t

bool samplePubSubType::getKey(void *data, InstanceHandle_t* handle, bool force_md5)
{
if(!m_isGetKeyDefined)
return false;
sample* p_type = static_cast<sample*>(data);
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(m_keyBuffer),sample::getKeyMaxCdrSerializedSize()); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // Object that serializes the data.
p_type->serializeKey(ser);
if(force_md5 || sample::getKeyMaxCdrSerializedSize()>16) {
m_md5.init();
m_md5.update(m_keyBuffer, static_cast<unsigned int>(ser.getSerializedDataLength()));
m_md5.finalize();
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_md5.digest[i];
}
}
else {
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_keyBuffer[i];
}
}
return true;
}

@davidhjp01
Copy link

davidhjp01 commented Nov 8, 2021

Hello, I posted related comments previously, just in case if it can help resolving this issue:
#2215 (comment)

@MiguelCompany
Copy link
Member

@WataruToishita @fujitatomoya @davidhjp01 Please check if #2316 solves your issues.

@fujitatomoya
Copy link
Contributor

@Barry-Xu-2018 could you try that out if the problem can be solved?

@WataruToishita
Copy link
Author

Hi @MiguelCompany,
I have verified #2316 and it solves this issue. Thank you!!

@Barry-Xu-2018
Copy link
Contributor

@Barry-Xu-2018 could you try that out if the problem can be solved.

After checking, #2316 can fix this problem.

@davidhjp01
Copy link

@WataruToishita @fujitatomoya @davidhjp01 Please check if #2316 solves your issues.

Seems it works on our side as well.

@fujitatomoya
Copy link
Contributor

@MiguelCompany we've done double check on this issue can be solved by #2316. please close this issue once #2316 is merged. appreciate it 👍

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

Successfully merging a pull request may close this issue.

5 participants