From: Remi Gacogne Date: Fri, 27 Aug 2021 09:39:23 +0000 (+0200) Subject: dnsdist: Use the 'checkTimeout' value for health-check queries X-Git-Tag: dnsdist-1.7.0-alpha1~23^2~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97b165e1d42b86dabbf0a7c85aea395510ce1d3e;p=thirdparty%2Fpdns.git dnsdist: Use the 'checkTimeout' value for health-check queries --- diff --git a/pdns/dnsdistdist/dnsdist-nghttp2.cc b/pdns/dnsdistdist/dnsdist-nghttp2.cc index 899391b187..14ceccd8f8 100644 --- a/pdns/dnsdistdist/dnsdist-nghttp2.cc +++ b/pdns/dnsdistdist/dnsdist-nghttp2.cc @@ -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 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& ds, std::unique_ptr(ds, mplexer, now); + newConnection->setHealthCheck(true); newConnection->queueQuery(sender, std::move(query)); return true; #else /* HAVE_NGHTTP2 */ diff --git a/pdns/dnsdistdist/dnsdist-tcp-downstream.hh b/pdns/dnsdistdist/dnsdist-tcp-downstream.hh index a34258cb90..2d79a90825 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-downstream.hh +++ b/pdns/dnsdistdist/dnsdist-tcp-downstream.hh @@ -146,6 +146,21 @@ protected: return !d_proxyProtocolPayloadSent && (d_ds && d_ds->useProxyProtocol); } + boost::optional 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 getBackendReadTTD(const struct timeval& now) const { if (d_ds == nullptr) {