]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Handle EAGAIN when reading from the non-blocking TCP pipe
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 21 Mar 2019 17:49:27 +0000 (18:49 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 4 Apr 2019 09:54:04 +0000 (11:54 +0200)
pdns/dnsdist-tcp.cc

index 97ca4c73e056080cfcd6948744e6262f74803b1e..ed9d896b5a103f6317ccbfda17dd4986102766e8 100644 (file)
@@ -992,11 +992,18 @@ static void handleIncomingTCPQuery(int pipefd, FDMultiplexer::funcparam_t& param
 
   ConnectionInfo* citmp{nullptr};
 
-  try {
-    readn2(pipefd, &citmp, sizeof(citmp));
+  ssize_t got = read(pipefd, &citmp, sizeof(citmp));
+  if (got == 0) {
+    throw std::runtime_error("EOF while reading from the TCP acceptor pipe (" + std::to_string(pipefd) + ") in " + std::string(isNonBlocking(pipefd) ? "non-blocking" : "blocking") + " mod");
+  }
+  else if (got == -1) {
+    if (errno == EAGAIN || errno == EINTR) {
+      return;
+    }
+    throw std::runtime_error("Error while reading from the TCP acceptor pipe (" + std::to_string(pipefd) + ") in " + std::string(isNonBlocking(pipefd) ? "non-blocking" : "blocking") + " mde:" + strerror(errno));
   }
-  catch(const std::runtime_error& e) {
-    throw std::runtime_error("Error reading from TCP acceptor pipe (" + std::to_string(pipefd) + ") in " + std::string(isNonBlocking(pipefd) ? "non-blocking" : "blocking") + " mode: " + e.what());
+  else if (got != sizeof(citmp)) {
+    throw std::runtime_error("Partial read while reading from the TCP acceptor pipe (" + std::to_string(pipefd) + ") in " + std::string(isNonBlocking(pipefd) ? "non-blocking" : "blocking") + " mode");
   }
 
   g_tcpclientthreads->decrementQueuedCount();