]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add a bit more output to the TCP states debug log
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 8 Feb 2021 15:52:45 +0000 (16:52 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 2 Mar 2021 09:49:15 +0000 (10:49 +0100)
pdns/dnsdist-tcp.cc
pdns/dnsdistdist/dnsdist-tcp-downstream.hh
pdns/dnsdistdist/dnsdist-tcp-upstream.hh

index f547a1b1a3d759121e004749edced57081ce6c5a..d3e3626e9e7de361e8dcec934e8a1f0a928cbcd0 100644 (file)
@@ -1014,12 +1014,25 @@ static void tcpClientThread(int pipefd)
       DownstreamConnectionsManager::cleanupClosedTCPConnections();
       lastTCPCleanup = now.tv_sec;
 
-      /*
+#if 0
+      /* just to keep things clean in the output, debug only */
+      static std::mutex s_lock;
+      std::lock_guard<decltype(s_lock)> lck(s_lock);
       data.mplexer->runForAllWatchedFDs([](bool isRead, int fd, const FDMultiplexer::funcparam_t& param, struct timeval ttd)
       {
-        cerr<<"- "<<isRead<<" "<<fd<<": "<<param.type().name()<<" "<<ttd.tv_sec<<endl;
+        struct timeval lnow;
+        gettimeofday(&lnow, 0);
+        cerr<<"- "<<isRead<<" "<<fd<<": "<<" "<<(ttd.tv_sec-lnow.tv_sec)<<endl;
+        if (param.type() == typeid(std::shared_ptr<IncomingTCPConnectionState>)) {
+          auto state = boost::any_cast<std::shared_ptr<IncomingTCPConnectionState>>(param);
+          cerr<<" - "<<state->toString()<<endl;
+        }
+        else if (param.type() == typeid(std::shared_ptr<TCPConnectionToBackend>)) {
+          auto conn = boost::any_cast<std::shared_ptr<TCPConnectionToBackend>>(param);
+          cerr<<" - "<<conn->toString()<<endl;
+        }
       });
-      */
+#endif
     }
 
     if (now.tv_sec > lastTimeoutScan) {
index 2ce536a8db95538674174caba11c049fd781433c..46b53a70ac1820955cd6feeec7355524b2941028 100644 (file)
@@ -169,6 +169,13 @@ public:
   void setProxyProtocolPayloadAdded(bool added);
   void setProxyProtocolValuesSent(std::unique_ptr<std::vector<ProxyProtocolValue>>&& proxyProtocolValuesSent);
 
+  std::string toString() const
+  {
+    ostringstream o;
+    o << "TCP connection to backend "<<(d_ds ? d_ds->getName() : "empty")<<" over FD "<<(d_socket ? std::to_string(d_socket->getHandle()) : "no socket")<<", state is "<<(int)d_state<<", io state is "<<(d_ioState ? std::to_string((int)d_ioState->getState()) : "empty")<<", queries count is "<<d_queries<<", pending queries count is "<<d_pendingQueries.size()<<", "<<d_pendingResponses.size()<<" pending responses, linked to "<<(d_clientConn ? " a client" : "no client");
+    return o.str();
+  }
+
 private:
   /* waitingForResponseFromBackend is a state where we have not yet started reading the size,
      so we can still switch to sending instead */
index 2b650a79500bef2526160be9803bac9a48af7fda..794b1518588b4a5bf6663262b5432bf2c7736ca5 100644 (file)
@@ -168,6 +168,13 @@ public:
     return d_ioState != nullptr;
   }
 
+  std::string toString() const
+  {
+    ostringstream o;
+    o << "Incoming TCP connection from "<<d_ci.remote.toStringWithPort()<<" over FD "<<d_ci.fd<<", state is "<<(int)d_state<<", io state is "<<(d_ioState ? std::to_string((int)d_ioState->getState()) : "empty")<<", queries count is "<<d_queriesCount<<", current queries count is "<<d_currentQueriesCount<<", "<<d_queuedResponses.size()<<" queued responses, "<<d_activeConnectionsToBackend.size()<<" active connections to a backend";
+    return o.str();
+  }
+
   enum class State { doingHandshake, readingProxyProtocolHeader, readingQuerySize, readingQuery, sendingResponse, idle /* in case of XFR, we stop processing queries */ };
 
   std::map<std::shared_ptr<DownstreamState>, std::deque<std::shared_ptr<TCPConnectionToBackend>>> d_activeConnectionsToBackend;