From ee88963ce56f2ada5443ffb7f44690947bbbfc5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez=20Moreno?= Date: Thu, 12 Aug 2021 09:35:35 +0200 Subject: [PATCH 1/3] Refs #12361. Fix wrong iterator after vector reallocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González Moreno --- src/cpp/rtps/writer/LivelinessManager.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cpp/rtps/writer/LivelinessManager.cpp b/src/cpp/rtps/writer/LivelinessManager.cpp index a507776704f..f7bd5adc774 100644 --- a/src/cpp/rtps/writer/LivelinessManager.cpp +++ b/src/cpp/rtps/writer/LivelinessManager.cpp @@ -61,6 +61,19 @@ bool LivelinessManager::add_writer( } } writers_.emplace_back(guid, kind, lease_duration); + + if (!calculate_next()) + { + timer_.cancel_timer(); + return false; + } + + // Some times the interval could be negative if a writer expired during the call to this function + // Once in this situation there is not much we can do but let asio timers expire inmediately + auto interval = timer_owner_->time - steady_clock::now(); + timer_.update_interval_millisec((double)duration_cast(interval).count()); + timer_.restart_timer(); + return true; } @@ -95,9 +108,8 @@ bool LivelinessManager::remove_writer( } } - if (timer_owner_ != nullptr && timer_owner_->guid == guid) + if (timer_owner_ != nullptr) { - timer_owner_ = nullptr; if (!calculate_next()) { timer_.cancel_timer(); From d87e06a7c08ca92611f8de3cc816670ae735a52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez=20Moreno?= Date: Thu, 12 Aug 2021 11:08:19 +0200 Subject: [PATCH 2/3] Refs #12361. Always return true adding a writer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González Moreno --- src/cpp/rtps/writer/LivelinessManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/rtps/writer/LivelinessManager.cpp b/src/cpp/rtps/writer/LivelinessManager.cpp index f7bd5adc774..08ca6f2d2c0 100644 --- a/src/cpp/rtps/writer/LivelinessManager.cpp +++ b/src/cpp/rtps/writer/LivelinessManager.cpp @@ -65,7 +65,7 @@ bool LivelinessManager::add_writer( if (!calculate_next()) { timer_.cancel_timer(); - return false; + return true; } // Some times the interval could be negative if a writer expired during the call to this function From e19c537fb3351b24a23c3456bdbc29636a81a33e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez?= Date: Fri, 13 Aug 2021 09:29:04 +0200 Subject: [PATCH 3/3] Update src/cpp/rtps/writer/LivelinessManager.cpp Co-authored-by: Eduardo Ponz Segrelles --- src/cpp/rtps/writer/LivelinessManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/rtps/writer/LivelinessManager.cpp b/src/cpp/rtps/writer/LivelinessManager.cpp index 08ca6f2d2c0..b48c61b53f8 100644 --- a/src/cpp/rtps/writer/LivelinessManager.cpp +++ b/src/cpp/rtps/writer/LivelinessManager.cpp @@ -69,7 +69,7 @@ bool LivelinessManager::add_writer( } // Some times the interval could be negative if a writer expired during the call to this function - // Once in this situation there is not much we can do but let asio timers expire inmediately + // Once in this situation there is not much we can do but let asio timers expire immediately auto interval = timer_owner_->time - steady_clock::now(); timer_.update_interval_millisec((double)duration_cast(interval).count()); timer_.restart_timer();