]> 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>
Fri, 6 Sep 2024 10:12:14 +0000 (12:12 +0200)
pdns/recursordist/lwres.cc
pdns/recursordist/pdns_recursor.cc
pdns/recursordist/syncres.hh

index 238fa20d0a350e104ec3ea5cd49dc2d26676ce1d..95bdb00f527806a687d740c65509806186b3ec07 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 e636cf57a86f1deae8b5bf01fe85bd38d6a9a82c..3aed8c4fcdb86d8deb162ea1f1911db0fd6e464d 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::ChainLimitError;
         }
@@ -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::ChainLimitError;
         }
-        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 9b14bf8d9194d5751a64e412d22fe0123cb9b324..02d8ef722ff9a5dc81eca46ddadc86ef188b16b5 100644 (file)
@@ -777,7 +777,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{};