]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Use the 'checkTimeout' value for health-check queries
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 27 Aug 2021 09:39:23 +0000 (11:39 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 13 Sep 2021 13:28:28 +0000 (15:28 +0200)
pdns/dnsdistdist/dnsdist-nghttp2.cc
pdns/dnsdistdist/dnsdist-tcp-downstream.hh

index 899391b187968da4243134a99a49a6e8a27e0190..14ceccd8f8bba7078b586169a1cfacd72e1fe75f 100644 (file)
@@ -59,6 +59,11 @@ public:
 
   bool canBeReused() const override;
 
+  void setHealthCheck(bool h)
+  {
+    d_healthCheckQuery = h;
+  }
+
 private:
   static ssize_t send_callback(nghttp2_session* session, const uint8_t* data, size_t length, int flags, void* user_data);
   static int on_frame_recv_callback(nghttp2_session* session, const nghttp2_frame* frame, void* user_data);
@@ -105,6 +110,7 @@ private:
   size_t d_outPos{0};
   size_t d_inPos{0};
   uint32_t d_highestStreamID{0};
+  bool d_healthCheckQuery{false};
 };
 
 class DownstreamDoHConnectionsManager
@@ -426,7 +432,10 @@ void DoHConnectionToBackend::updateIO(IOState newState, FDMultiplexer::callbackf
   struct timeval now;
   gettimeofday(&now, nullptr);
   boost::optional<struct timeval> ttd{boost::none};
-  if (newState == IOState::NeedRead) {
+  if (d_healthCheckQuery) {
+    ttd = getBackendHealthCheckTTD(now);
+  }
+  else if (newState == IOState::NeedRead) {
     ttd = getBackendReadTTD(now);
   }
   else if (isFresh() && d_queries == 0) {
@@ -1126,6 +1135,7 @@ bool sendH2Query(const std::shared_ptr<DownstreamState>& ds, std::unique_ptr<FDM
   gettimeofday(&now, nullptr);
 
   auto newConnection = std::make_shared<DoHConnectionToBackend>(ds, mplexer, now);
+  newConnection->setHealthCheck(true);
   newConnection->queueQuery(sender, std::move(query));
   return true;
 #else /* HAVE_NGHTTP2 */
index a34258cb9005873b62a11139c4d0bc04ed73aba0..2d79a908250fa755643ee8077d2a328f3c6baf24 100644 (file)
@@ -146,6 +146,21 @@ protected:
     return !d_proxyProtocolPayloadSent && (d_ds && d_ds->useProxyProtocol);
   }
 
+  boost::optional<struct timeval> getBackendHealthCheckTTD(const struct timeval& now) const
+  {
+    if (d_ds == nullptr) {
+      throw std::runtime_error("getBackendReadTTD() without any backend selected");
+    }
+    if (d_ds->checkTimeout == 0) {
+      return boost::none;
+    }
+
+    struct timeval res = now;
+    res.tv_sec += d_ds->checkTimeout;
+
+    return res;
+  }
+
   boost::optional<struct timeval> getBackendReadTTD(const struct timeval& now) const
   {
     if (d_ds == nullptr) {