]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Better handling of outgoing DoH workers 10772/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 28 Sep 2021 13:38:42 +0000 (15:38 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 28 Sep 2021 13:38:42 +0000 (15:38 +0200)
This commit raises the number of DoH workers to be at least 1, always, unless
told otherwise via setOutgoingDoHWorkerThreads(0).
In that last case it raises an exception if the console is used to declare
a new DoH backend later on.

pdns/dnsdist-lua.cc
pdns/dnsdistdist/dnsdist-nghttp2.cc
pdns/dnsdistdist/dnsdist-nghttp2.hh

index c5daacf693c99a94681f14832fab8e76c8d0e73b..2aaa8d3df90a2913c6549716b02e310227d744f7 100644 (file)
@@ -536,7 +536,12 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
           if (ret->d_tlsCtx) {
             setupDoHClientProtocolNegotiation(ret->d_tlsCtx);
           }
-          if (g_outgoingDoHWorkerThreads == 0) {
+
+          if (g_configurationDone && g_outgoingDoHWorkerThreads && *g_outgoingDoHWorkerThreads == 0) {
+            throw std::runtime_error("Error: setOutgoingDoHWorkerThreads() is set to 0 so no outgoing DoH worker thread is available to serve queries");
+          }
+
+          if (!g_outgoingDoHWorkerThreads || *g_outgoingDoHWorkerThreads == 0) {
             g_outgoingDoHWorkerThreads = 1;
           }
 
index abebdec1b4353da6e2097257b45455e56e49e35d..0f1e78d8fac144efc048ba91bb375e4811887963 100644 (file)
@@ -40,7 +40,7 @@
 
 std::atomic<uint64_t> g_dohStatesDumpRequested{0};
 std::unique_ptr<DoHClientCollection> g_dohClientThreads{nullptr};
-uint16_t g_outgoingDoHWorkerThreads{0};
+std::optional<uint16_t> g_outgoingDoHWorkerThreads{std::nullopt};
 
 #ifdef HAVE_NGHTTP2
 class DoHConnectionToBackend : public TCPConnectionToBackend
@@ -1229,9 +1229,15 @@ void DoHClientCollection::addThread()
 bool initDoHWorkers()
 {
 #ifdef HAVE_NGHTTP2
-  if (g_outgoingDoHWorkerThreads > 0) {
-    g_dohClientThreads = std::make_unique<DoHClientCollection>(g_outgoingDoHWorkerThreads);
-    for (size_t idx = 0; idx < g_outgoingDoHWorkerThreads; idx++) {
+  if (!g_outgoingDoHWorkerThreads) {
+    /* Unless the value has been set to 0 explicitly, always start at least one outgoing DoH worker thread, in case a DoH backend
+       is added at a later time. */
+    g_outgoingDoHWorkerThreads = 1;
+  }
+
+  if (g_outgoingDoHWorkerThreads && *g_outgoingDoHWorkerThreads > 0) {
+    g_dohClientThreads = std::make_unique<DoHClientCollection>(*g_outgoingDoHWorkerThreads);
+    for (size_t idx = 0; idx < *g_outgoingDoHWorkerThreads; idx++) {
       g_dohClientThreads->addThread();
     }
   }
index f57e4e46faecc8050f76ae8f3ef2eeb14396e2ac..a44930f4cabce5e56e5c32e93e2a62d05c870617 100644 (file)
@@ -57,7 +57,7 @@ private:
 
 extern std::unique_ptr<DoHClientCollection> g_dohClientThreads;
 extern std::atomic<uint64_t> g_dohStatesDumpRequested;
-extern uint16_t g_outgoingDoHWorkerThreads;
+extern std::optional<uint16_t> g_outgoingDoHWorkerThreads;
 
 class TLSCtx;