From: Otto Moerbeek Date: Fri, 6 Sep 2024 10:12:14 +0000 (+0200) Subject: rec: avoid duplicated waiter ids for chained requests X-Git-Tag: rec-5.2.0-alpha1~95^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b04c64e61cd7b3440ea014da375f47114fe9364b;p=thirdparty%2Fpdns.git rec: avoid duplicated waiter ids for chained requests --- diff --git a/pdns/recursordist/lwres.cc b/pdns/recursordist/lwres.cc index 238fa20d0a..95bdb00f52 100644 --- a/pdns/recursordist/lwres.cc +++ b/pdns/recursordist/lwres.cc @@ -484,7 +484,7 @@ static LWResult::Result asyncresolve(const ComboAddress& address, const DNSName& return ret; } - if (queryfd == -1) { + if (queryfd <= -1) { *chained = true; } diff --git a/pdns/recursordist/pdns_recursor.cc b/pdns/recursordist/pdns_recursor.cc index e636cf57a8..3aed8c4fcd 100644 --- a/pdns/recursordist/pdns_recursor.cc +++ b/pdns/recursordist/pdns_recursor.cc @@ -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(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(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_ptrkey->authReqChain) { + for (auto [fileDesc, qid] : iter->key->authReqChain) { auto packetID = std::make_shared(*resend); - packetID->fd = -1; + packetID->fd = fileDesc; packetID->id = qid; g_multiTasker->sendEvent(packetID, &content); t_Counters.at(rec::Counter::chainResends)++; diff --git a/pdns/recursordist/syncres.hh b/pdns/recursordist/syncres.hh index 9b14bf8d91..02d8ef722f 100644 --- a/pdns/recursordist/syncres.hh +++ b/pdns/recursordist/syncres.hh @@ -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; + using chain_t = set>; mutable chain_t authReqChain; shared_ptr tcphandler{nullptr}; timeval creationTime{};