]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Decrement the queued TCP conn count if writing to the pipe fails 4742/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 5 Dec 2016 17:01:55 +0000 (18:01 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 5 Dec 2016 17:01:55 +0000 (18:01 +0100)
Otherwise we might end up refusing every new TCP connection until
we are restarted.

pdns/dnsdist-tcp.cc

index 9d9f956872ece4168eb257e70316c0409025b670..3076c72c11570d746290e486cb11ad28819d4bca 100644 (file)
@@ -524,9 +524,9 @@ void* tcpAcceptorThread(void* p)
 
   auto acl = g_ACL.getLocal();
   for(;;) {
-    ConnectionInfo* ci;
+    bool queuedCounterIncremented = false;
+    ConnectionInfo* ci = nullptr;
     try {
-      ci=0;
       ci = new ConnectionInfo;
       ci->cs = cs;
       ci->fd = -1;
@@ -536,7 +536,7 @@ void* tcpAcceptorThread(void* p)
        g_stats.aclDrops++;
        close(ci->fd);
        delete ci;
-       ci=0;
+       ci=nullptr;
        vinfolog("Dropped TCP connection from %s because of ACL", remote.toStringWithPort());
        continue;
       }
@@ -554,10 +554,12 @@ void* tcpAcceptorThread(void* p)
       ci->remote = remote;
       int pipe = g_tcpclientthreads->getThread();
       if (pipe >= 0) {
+        queuedCounterIncremented = true;
         writen2WithTimeout(pipe, &ci, sizeof(ci), 0);
       }
       else {
         --g_tcpclientthreads->d_queued;
+        queuedCounterIncremented = false;
         close(ci->fd);
         delete ci;
         ci=nullptr;
@@ -568,6 +570,10 @@ void* tcpAcceptorThread(void* p)
       if(ci && ci->fd >= 0) 
        close(ci->fd);
       delete ci;
+      ci = nullptr;
+      if (queuedCounterIncremented) {
+        --g_tcpclientthreads->d_queued;
+      }
     }
     catch(...){}
   }