From: Remi Gacogne Date: Fri, 9 Dec 2016 16:08:04 +0000 (+0100) Subject: dnsdist: Better handling of failures during TCP worker thread creation X-Git-Tag: dnsdist-1.1.0-beta2~7^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=adbf75f76b6303c44d7e480d73a0f33a7bef7c18;p=thirdparty%2Fpdns.git dnsdist: Better handling of failures during TCP worker thread creation --- diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 4b22236801..a805b8906e 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -81,19 +81,32 @@ void TCPClientCollection::addTCPClientThread() vinfolog("Adding TCP Client thread"); int pipefds[2] = { -1, -1}; - if(pipe(pipefds) < 0) - unixDie("Creating pipe"); + if (pipe(pipefds) < 0) { + errlog("Error creating the TCP thread communication pipe: %s", strerror(errno)); + return; + } if (!setNonBlocking(pipefds[1])) { close(pipefds[0]); close(pipefds[1]); - unixDie("Setting pipe non-blocking"); + errlog("Error setting the TCP thread communication pipe non-blocking: %s", strerror(errno)); + return; + } + + try { + thread t1(tcpClientThread, pipefds[0]); + t1.detach(); + } + catch(const std::runtime_error& e) { + /* the thread creation failed, don't leak */ + errlog("Error creating a TCP thread: %s", e.what()); + close(pipefds[0]); + close(pipefds[1]); + return; } d_tcpclientthreads.push_back(pipefds[1]); ++d_numthreads; - thread t1(tcpClientThread, pipefds[0]); - t1.detach(); } static bool getNonBlockingMsgLen(int fd, uint16_t* len, int timeout)