]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Better handling of failures during TCP worker thread creation
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 9 Dec 2016 16:08:04 +0000 (17:08 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 9 Dec 2016 16:08:04 +0000 (17:08 +0100)
pdns/dnsdist-tcp.cc

index 4b22236801196962acc1ba418f05a0b3d63deecb..a805b8906e414c532c40366d50a70ca7dc910791 100644 (file)
@@ -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)