diff --git a/src/cpp/rtps/reader/StatefulReader.cpp b/src/cpp/rtps/reader/StatefulReader.cpp index 1cd27d4ddd5..7a1f8c5c7ce 100644 --- a/src/cpp/rtps/reader/StatefulReader.cpp +++ b/src/cpp/rtps/reader/StatefulReader.cpp @@ -932,8 +932,10 @@ bool StatefulReader::process_gap_msg( // TODO (Miguel C): Refactor this inside WriterProxy SequenceNumber_t auxSN; SequenceNumber_t finalSN = gapList.base(); + // Avoids iterating over sequence numbers already known irrelevant or processed + SequenceNumber_t startSN = std::max(gapStart, pWP->available_changes_max()); History::const_iterator history_iterator = history_->changesBegin(); - for (auxSN = gapStart; auxSN < finalSN; auxSN++) + for (auxSN = startSN; auxSN < finalSN; auxSN++) { if (pWP->irrelevant_change_set(auxSN)) { diff --git a/src/cpp/rtps/writer/StatefulWriter.cpp b/src/cpp/rtps/writer/StatefulWriter.cpp index 3133c98c407..a7fe361a6e7 100644 --- a/src/cpp/rtps/writer/StatefulWriter.cpp +++ b/src/cpp/rtps/writer/StatefulWriter.cpp @@ -1453,6 +1453,16 @@ void StatefulWriter::check_acked_status() } ); + // In situation that there are recently matched readers to the writer has not yet + // sent changes, both 'min_low_mark = zero' and 'all_acked == true' will be met. + // In this scenario, onWriterChangeReceivedByAll() will be skipped for the acked + // changes, that causes the changes to remain in history indefinitely. + // To prevent this condition, clip min_low_mark to handle the acked changes. + if (all_acked) + { + min_low_mark = history_->next_sequence_number() - 1; + } + bool something_changed = all_acked; SequenceNumber_t min_seq = get_seq_num_min(); if (min_seq != SequenceNumber_t::unknown())