]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: avoid duplicated waiter ids for chained requests
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 6 Sep 2024 10:12:14 +0000 (12:12 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 15 Oct 2024 12:27:05 +0000 (14:27 +0200)
(cherry picked from commit b04c64e61cd7b3440ea014da375f47114fe9364b)

pdns/recursordist/lwres.cc
pdns/recursordist/pdns_recursor.cc
pdns/recursordist/syncres.hh

index 04e29920d1d0d80b307ccbcc8fcc80ccc0935daf..8cbf8a853fa1cba4a6ef8d90a3fe3ff42ed309ca 100644 (file)
@@ -484,7 +484,7 @@ static LWResult::Result asyncresolve(const ComboAddress& address, const DNSName&
       return ret;
     }
 
-    if (queryfd == -1) {
+    if (queryfd <= -1) {
       *chained = true;
     }
 
index 6f9b2839a1426936c8fd4bb673cce046eb6c441f..4f5f26046ac8e562505b30138f8b3339f3707280 100644 (file)
@@ -305,8 +305,8 @@ LWResult::Result asendto(const void* data, size_t len, int /* flags */,
       assert(chain.first->key->domain == pident->domain); // NOLINT
       // don't chain onto existing chained waiter or a chain already processed
       if (chain.first->key->fd > -1 && !chain.first->key->closed) {
-        *fileDesc = -1; // gets used in waitEvent / sendEvent later on
         auto currentChainSize = chain.first->key->authReqChain.size();
+        *fileDesc = -static_cast<int>(currentChainSize + 1); // value <= -1, gets used in waitEvent / sendEvent later on
         if (g_maxChainLength > 0 && currentChainSize >= g_maxChainLength) {
           return LWResult::Result::OSLimitError;
         }
@@ -315,7 +315,7 @@ LWResult::Result asendto(const void* data, size_t len, int /* flags */,
         if (uSec(age) > static_cast<uint64_t>(1000) * authWaitTimeMSec(g_multiTasker) * 2 / 3) {
           return LWResult::Result::OSLimitError;
         }
-        chain.first->key->authReqChain.insert(qid); // we can chain
+        chain.first->key->authReqChain.emplace(*fileDesc, qid); // we can chain
         auto maxLength = t_Counters.at(rec::Counter::maxChainLength);
         if (currentChainSize > maxLength) {
           t_Counters.at(rec::Counter::maxChainLength) = currentChainSize;
@@ -2896,9 +2896,9 @@ static void doResends(MT_t::waiters_t::iterator& iter, const std::shared_ptr<Pac
     t_Counters.at(rec::Counter::maxChainWeight) = weight;
   }
 
-  for (auto qid : iter->key->authReqChain) {
+  for (auto [fileDesc, qid] : iter->key->authReqChain) {
     auto packetID = std::make_shared<PacketID>(*resend);
-    packetID->fd = -1;
+    packetID->fd = fileDesc;
     packetID->id = qid;
     g_multiTasker->sendEvent(packetID, &content);
     t_Counters.at(rec::Counter::chainResends)++;
index ebf0005e98933a8d238ef7fc7c37ba7a7b0b86aa..eb33f9e07de4a3a7bfee989f8ad45b0b652168ac 100644 (file)
@@ -763,7 +763,7 @@ struct PacketID
   PacketBuffer inMSG; // they'll go here
   PacketBuffer outMSG; // the outgoing message that needs to be sent
 
-  using chain_t = set<uint16_t>;
+  using chain_t = set<std::pair<int, uint16_t>>;
   mutable chain_t authReqChain;
   shared_ptr<TCPIOHandler> tcphandler{nullptr};
   timeval creationTime{};