]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add more information when readn2 fails because of EAGAIN 3564/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 14 Mar 2016 09:22:08 +0000 (10:22 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 14 Mar 2016 09:22:08 +0000 (10:22 +0100)
pdns/dnsdist-tcp.cc
pdns/misc.cc
pdns/misc.hh

index 2cb75474b76eaaef29e294a278d5e40a763ae589..d4320e7aabbf7340725881a6640d1e73a0fbf8dc 100644 (file)
@@ -160,7 +160,13 @@ void* tcpClientThread(int pipefd)
   for(;;) {
     ConnectionInfo* citmp, ci;
 
-    readn2(pipefd, &citmp, sizeof(citmp));
+    try {
+      readn2(pipefd, &citmp, sizeof(citmp));
+    }
+    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());
+    }
+
     --g_tcpclientthreads->d_queued;
     ci=*citmp;
     delete citmp;    
@@ -366,7 +372,7 @@ void* tcpClientThread(int pipefd)
          break;
        }
 
-       int dsock;
+       int dsock = -1;
        if(sockets.count(ds->remote) == 0) {
          dsock=sockets[ds->remote]=setupTCPDownstream(ds);
        }
@@ -387,6 +393,7 @@ void* tcpClientThread(int pipefd)
         if (ds->retries > 0 && downstream_failures > ds->retries) {
           vinfolog("Downstream connection to %s failed %d times in a row, giving up.", ds->getName(), downstream_failures);
           close(dsock);
+          dsock=-1;
           sockets.erase(ds->remote);
           break;
         }
@@ -608,6 +615,7 @@ void* tcpAcceptorThread(void* p)
         --g_tcpclientthreads->d_queued;
         close(ci->fd);
         delete ci;
+        ci=nullptr;
       }
     }
     catch(std::exception& e) {
index e4eb2d58a9355893c9caeadc8b5ff573e09dc606..1b7a545b134906997e47ee3a3c67e5e89fc0334a 100644 (file)
@@ -1063,6 +1063,12 @@ bool setBlocking(int sock)
   return true;
 }
 
+bool isNonBlocking(int sock)
+{
+  int flags=fcntl(sock,F_GETFL,0);
+  return flags & O_NONBLOCK;
+}
+
 // Closes a socket.
 int closesocket( int socket )
 {
index d9e6f9f8c487ac13cde1577ada03c7ac487d80a2..7b2713fbf5bb148a117929376d3107c9fbf9f23f 100644 (file)
@@ -600,6 +600,7 @@ bool setBlocking( int sock );
 
 //! Sets the socket into non-blocking mode.
 bool setNonBlocking( int sock );
+bool isNonBlocking(int sock);
 int closesocket(int fd);
 bool setCloseOnExec(int sock);
 uint64_t udpErrorStats(const std::string& str);