]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Factor duplicated code.
authorMiod Vallat <miod.vallat@powerdns.com>
Fri, 24 Oct 2025 09:32:30 +0000 (11:32 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Fri, 24 Oct 2025 09:32:30 +0000 (11:32 +0200)
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
pdns/auth-secondarycommunicator.cc
pdns/communicator.hh

index 25bf76974a9c91fba90d97f87de3e4538e7410c3..ea224b8f18857a0bc178247a95daf5b6ac70416a 100644 (file)
@@ -1016,18 +1016,10 @@ void CommunicatorClass::suck(const ZoneName& domain, const ComboAddress& remote,
   }
   catch (ResolverException& re) {
     {
-      auto data = d_data.lock();
       // The AXFR probably failed due to a problem on the primary server. If SOA-checks against this primary
       // still succeed, we would constantly try to AXFR the zone. To avoid this, we add the zone to the list of
       // failed secondary-checks. This will suspend secondary-checks (and subsequent AXFR) for this zone for some time.
-      uint64_t newCount = 1;
-      time_t now = time(nullptr);
-      const auto failedEntry = data->d_failedSecondaryRefresh.find(domain);
-      if (failedEntry != data->d_failedSecondaryRefresh.end()) {
-        newCount = data->d_failedSecondaryRefresh[domain].first + 1;
-      }
-      time_t nextCheck = now + std::min(newCount * d_tickinterval, (uint64_t)::arg().asNum("default-ttl")); // NOLINT(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
-      data->d_failedSecondaryRefresh[domain] = {newCount, nextCheck};
+      auto [newCount, nextCheck] = markAsFailed(domain);
       g_log << Logger::Warning << logPrefix << "unable to xfr zone (ResolverException): " << re.reason << " (This was attempt number " << newCount << ". Excluding zone from secondary-checks until " << humanTime(nextCheck) << ")" << endl;
     }
     if (ctx.domain.backend != nullptr && transaction) {
@@ -1308,14 +1300,7 @@ void CommunicatorClass::secondaryRefresh(PacketHandler* P) // NOLINT(readability
     }
 
     if (ssr.d_freshness.count(di.id) == 0) { // If we don't have an answer for the domain
-      uint64_t newCount = 1;
-      auto data = d_data.lock();
-      const auto failedEntry = data->d_failedSecondaryRefresh.find(di.zone);
-      if (failedEntry != data->d_failedSecondaryRefresh.end()) {
-        newCount = data->d_failedSecondaryRefresh[di.zone].first + 1;
-      }
-      time_t nextCheck = now + std::min(newCount * d_tickinterval, (uint64_t)::arg().asNum("default-ttl")); // NOLINT(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
-      data->d_failedSecondaryRefresh[di.zone] = {newCount, nextCheck};
+      auto [newCount, nextCheck] = markAsFailed(di.zone);
       if (newCount == 1) {
         g_log << Logger::Warning << "Unable to retrieve SOA for " << di.zone << ", this was the first time. NOTE: For every subsequent failed SOA check the domain will be suspended from freshness checks for 'num-errors x " << d_tickinterval << " seconds', with a maximum of " << (uint64_t)::arg().asNum("default-ttl") << " seconds. Skipping SOA checks until " << humanTime(nextCheck) << endl;
       }
@@ -1437,3 +1422,17 @@ size_t CommunicatorClass::getSuckRequestsWaiting()
 {
   return d_data.lock()->d_suckdomains.size();
 }
+
+std::pair<uint64_t, time_t> CommunicatorClass::markAsFailed(const ZoneName& domain)
+{
+  uint64_t newCount = 1;
+  auto data = d_data.lock();
+  time_t now = time(nullptr);
+  const auto failedEntry = data->d_failedSecondaryRefresh.find(domain);
+  if (failedEntry != data->d_failedSecondaryRefresh.end()) {
+    newCount = data->d_failedSecondaryRefresh[domain].first + 1;
+  }
+  time_t nextCheck = now + std::min(newCount * d_tickinterval, (uint64_t)::arg().asNum("default-ttl")); // NOLINT(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
+  data->d_failedSecondaryRefresh[domain] = {newCount, nextCheck};
+  return std::make_pair(newCount, nextCheck);
+}
index c4506cc1bb58b391ef60b83c7fc1d38507b011ef..f75f484b6e2cb12d0454ff27328d641fca685617 100644 (file)
@@ -195,6 +195,7 @@ private:
   void secondaryRefresh(PacketHandler* P);
   void primaryUpdateCheck(PacketHandler* P);
   void getUpdatedProducers(UeberBackend* B, vector<DomainInfo>& domains, const std::unordered_set<DNSName>& catalogs, CatalogHashMap& catalogHashes);
+  std::pair<uint64_t, time_t> markAsFailed(const ZoneName& domain);
 
   Semaphore d_suck_sem;
   Semaphore d_any_sem;