From 1287674c13b42772b13dd2ad40c2b8b9816c9f45 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 17 Feb 2016 12:34:39 +0100 Subject: [PATCH] dnsdist: Better handling of outstanding counter The outstanding value is now displayed in `showServers()` and we set the IDS age to 0 as soon as we get a response to prevent the maintainer thread from cleaning it up during our processing. --- pdns/dnsdist-lua.cc | 10 +++++----- pdns/dnsdist.cc | 9 ++++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 32fc83282..77f63075c 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -501,9 +501,9 @@ vector> setupLua(bool client, const std::string& confi setLuaNoSideEffect(); try { ostringstream ret; - boost::format fmt("%1$-3d %2$-20.20s %|25t|%3% %|55t|%4$5s %|51t|%5$7.1f %|66t|%6$7d %|69t|%7$3d %|78t|%8$2d %|80t|%9$10d %|86t|%10$7d %|91t|%11$5.1f %|109t|%12$5.1f %13%" ); - // 1 2 3 4 5 6 7 8 9 10 11 12 - ret << (fmt % "#" % "Name" % "Address" % "State" % "Qps" % "Qlim" % "Ord" % "Wt" % "Queries" % "Drops" % "Drate" % "Lat" % "Pools") << endl; + boost::format fmt("%1$-3d %2$-20.20s %|25t|%3% %|55t|%4$5s %|51t|%5$7.1f %|66t|%6$7d %|69t|%7$3d %|78t|%8$2d %|80t|%9$10d %|86t|%10$7d %|91t|%11$5.1f %|109t|%12$5.1f %|115t|%13$11d %14%" ); + // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 + ret << (fmt % "#" % "Name" % "Address" % "State" % "Qps" % "Qlim" % "Ord" % "Wt" % "Queries" % "Drops" % "Drate" % "Lat" % "Outstanding" % "Pools") << endl; uint64_t totQPS{0}, totQueries{0}, totDrops{0}; int counter=0; @@ -526,7 +526,7 @@ vector> setupLua(bool client, const std::string& confi ret << (fmt % counter % s->name % s->remote.toStringWithPort() % status % - s->queryLoad % s->qps.getRate() % s->order % s->weight % s->queries.load() % s->reuseds.load() % (s->dropRate) % (s->latencyUsec/1000.0) % pools) << endl; + s->queryLoad % s->qps.getRate() % s->order % s->weight % s->queries.load() % s->reuseds.load() % (s->dropRate) % (s->latencyUsec/1000.0) % s->outstanding.load() % pools) << endl; totQPS += s->queryLoad; totQueries += s->queries.load(); @@ -535,7 +535,7 @@ vector> setupLua(bool client, const std::string& confi } ret<< (fmt % "All" % "" % "" % "" % - (double)totQPS % "" % "" % "" % totQueries % totDrops % "" % "" % "" ) << endl; + (double)totQPS % "" % "" % "" % totQueries % totDrops % "" % "" % "" % "" ) << endl; g_outputBuffer=ret.str(); }catch(std::exception& e) { g_outputBuffer=e.what(); throw; } diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 560d59890..5121e64dc 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -181,8 +181,15 @@ void* responderThread(std::shared_ptr state) if(origFD < 0) // duplicate continue; - else + else { + /* setting age to 0 to prevent the maintainer thread from + cleaning this IDS while we process the response. + We have already a copy of the origFD, so it would + mostly mess up the outstanding counter. + */ + ids->age = 0; --state->outstanding; // you'd think an attacker could game this, but we're using connected socket + } if(g_fixupCase) { string realname = ids->qname.toDNSString(); -- 2.40.0