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

Fix crash when disable_positive_acks is enable and the remote reader is best-effort [17338] (backport #3324) #3386

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/cpp/rtps/writer/StatefulWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,6 @@ void StatefulWriter::unsent_change_added_to_history(
}
);

if (should_be_sent)
{
flow_controller_->add_new_sample(this, change, max_blocking_time);
}
else
{
periodic_hb_event_->restart_timer(max_blocking_time);
}

if (disable_positive_acks_)
{
auto source_timestamp = system_clock::time_point() + nanoseconds(change->sourceTimestamp.to_ns());
Expand All @@ -454,6 +445,17 @@ void StatefulWriter::unsent_change_added_to_history(
ack_event_->update_interval_millisec((double)duration_cast<milliseconds>(interval).count());
ack_event_->restart_timer(max_blocking_time);
}

// After adding the CacheChange_t to flowcontroller, its pointer cannot be used because it may be removed
// internally before exiting the call. For example if the writer matched with a best-effort reader.
if (should_be_sent)
{
flow_controller_->add_new_sample(this, change, max_blocking_time);
}
else
{
periodic_hb_event_->restart_timer(max_blocking_time);
}
}
else
{
Expand Down
34 changes: 34 additions & 0 deletions test/blackbox/common/BlackboxTestsAcknackQos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,37 @@ TEST(AcknackQos, NotRecoverAfterLosingCommunicationWithDisablePositiveAck)
// Block reader until reception finished or timeout.
ASSERT_EQ(reader.block_for_all(std::chrono::seconds(1)), 0u);
}

/*!
* @test Regresion test for Github #3323.
*/
TEST(AcknackQos, DisablePositiveAcksWithBestEffortReader)
{
PubSubReader<HelloWorldPubSubType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldPubSubType> writer(TEST_TOPIC_NAME);

writer.keep_duration({2, 0});
writer.reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS);
writer.durability_kind(eprosima::fastrtps::VOLATILE_DURABILITY_QOS);
writer.init();

reader.keep_duration({1, 0});
reader.reliability(eprosima::fastrtps::BEST_EFFORT_RELIABILITY_QOS);
reader.init();

ASSERT_TRUE(reader.isInitialized());
ASSERT_TRUE(writer.isInitialized());

// Wait for discovery.
writer.wait_discovery();
reader.wait_discovery();

std::list<HelloWorld> data = default_helloworld_data_generator();
reader.startReception(data);
// Send data
writer.send(data);
// In this test all data should be sent.
ASSERT_TRUE(data.empty());
// Block reader until reception finished or timeout.
reader.block_for_all();
}