From: Francis Dupont Date: Sat, 28 Mar 2020 13:36:10 +0000 (+0100) Subject: [#1095] Protected communication state timer concurrent accesses X-Git-Tag: Kea-1.7.8~142 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de0bafbfed8e010ea0f08afef740885b1c7d1361;p=thirdparty%2Fkea.git [#1095] Protected communication state timer concurrent accesses --- diff --git a/src/hooks/dhcp/high_availability/communication_state.cc b/src/hooks/dhcp/high_availability/communication_state.cc index f948976a29..a0414c8d78 100644 --- a/src/hooks/dhcp/high_availability/communication_state.cc +++ b/src/hooks/dhcp/high_availability/communication_state.cc @@ -46,7 +46,8 @@ namespace ha { CommunicationState::CommunicationState(const IOServicePtr& io_service, const HAConfigPtr& config) - : io_service_(io_service), config_(config), timer_(), interval_(0), + : io_service_(io_service), config_(config), timer_(), + timer_mutex_(new std::mutex()), interval_(0), poke_time_(boost::posix_time::microsec_clock::universal_time()), heartbeat_impl_(0), partner_state_(-1), partner_scopes_(), clock_skew_(0, 0, 0, 0), last_clock_skew_warn_(), @@ -93,6 +94,7 @@ CommunicationState::setPartnerScopes(ConstElementPtr new_scopes) { void CommunicationState::startHeartbeat(const long interval, const boost::function& heartbeat_impl) { + std::lock_guard lock(*timer_mutex_); startHeartbeatInternal(interval, heartbeat_impl); } @@ -139,6 +141,7 @@ CommunicationState::startHeartbeatInternal(const long interval, void CommunicationState::stopHeartbeat() { + std::lock_guard lock(*timer_mutex_); if (timer_) { timer_->cancel(); timer_.reset(); @@ -159,6 +162,7 @@ CommunicationState::poke() { // seems to be (re)established. clearUnackedClients(); + std::lock_guard lock(*timer_mutex_); if (timer_) { // Check the duration since last poke. If it is less than a second, we don't // want to reschedule the timer. The only case when the poke time duration is diff --git a/src/hooks/dhcp/high_availability/communication_state.h b/src/hooks/dhcp/high_availability/communication_state.h index 1ced58daec..9d0966dc54 100644 --- a/src/hooks/dhcp/high_availability/communication_state.h +++ b/src/hooks/dhcp/high_availability/communication_state.h @@ -1,4 +1,4 @@ -// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -134,6 +135,7 @@ public: /// /// @return true if heartbeat is running, false otherwise. bool isHeartbeatRunning() const { + std::lock_guard lock(*timer_mutex_); return (static_cast(timer_)); } @@ -306,6 +308,9 @@ protected: /// @brief Interval timer triggering heartbeat commands. asiolink::IntervalTimerPtr timer_; + /// @brief Mutex to protect timer_ concurrent accesses. + boost::shared_ptr timer_mutex_; + /// @brief Interval specified for the heartbeat. long interval_;