diff --git a/src/cpp/fastdds/subscriber/DataReaderImpl.cpp b/src/cpp/fastdds/subscriber/DataReaderImpl.cpp index cfc30b84598..179fc63203b 100644 --- a/src/cpp/fastdds/subscriber/DataReaderImpl.cpp +++ b/src/cpp/fastdds/subscriber/DataReaderImpl.cpp @@ -688,11 +688,6 @@ ReturnCode_t DataReaderImpl::read_or_take_next_sample( return ReturnCode_t::RETCODE_NOT_ENABLED; } - if (history_.getHistorySize() == 0) - { - return ReturnCode_t::RETCODE_NO_DATA; - } - auto max_blocking_time = std::chrono::steady_clock::now() + #if HAVE_STRICT_REALTIME std::chrono::microseconds(::TimeConv::Time_t2MicroSecondsInt64(qos_.reliability().max_blocking_time)); @@ -707,6 +702,16 @@ ReturnCode_t DataReaderImpl::read_or_take_next_sample( return ReturnCode_t::RETCODE_TIMEOUT; } + auto unread_count = get_unread_count(false); + if (history_.getHistorySize() == 0) + { + auto unread_count_no_history = get_unread_count(false); + assert(unread_count_no_history != unread_count || unread_count_no_history == 0); + // assert(get_unread_count() == 0); + return ReturnCode_t::RETCODE_NO_DATA; + } + + set_read_communication_status(false); auto it = history_.lookup_available_instance(HANDLE_NIL, false); diff --git a/src/cpp/rtps/reader/StatefulReader.cpp b/src/cpp/rtps/reader/StatefulReader.cpp index c1232442e48..7b43ada3eed 100644 --- a/src/cpp/rtps/reader/StatefulReader.cpp +++ b/src/cpp/rtps/reader/StatefulReader.cpp @@ -953,6 +953,10 @@ bool StatefulReader::change_removed_by_history( { --total_unread_; } + else + { + assert(false); + } } WriterProxy* proxy = wp; @@ -1159,6 +1163,7 @@ void StatefulReader::NotifyChanges( assert(false == aux_ch->isRead); new_data_available = true; ++total_unread_; + assert(total_unread_ <= mp_history->getHistorySize()); on_data_notify(proxGUID, aux_ch->sourceTimestamp); ++it; @@ -1425,11 +1430,16 @@ void StatefulReader::change_read_by_user( // Mark change as read if (mark_as_read && !change->isRead) { + assert(get_last_notified(change->writerGUID) >= change->sequenceNumber); change->isRead = true; if (0 < total_unread_) { --total_unread_; } + else + { + assert(false); + } } if (mark_as_read)