From: Remi Gacogne Date: Mon, 5 Dec 2016 17:01:55 +0000 (+0100) Subject: dnsdist: Decrement the queued TCP conn count if writing to the pipe fails X-Git-Tag: dnsdist-1.1.0-beta2~22^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F4742%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Decrement the queued TCP conn count if writing to the pipe fails Otherwise we might end up refusing every new TCP connection until we are restarted. --- diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 9d9f956872..3076c72c11 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -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(...){} }