From: Remi Gacogne Date: Thu, 21 Mar 2019 17:49:27 +0000 (+0100) Subject: dnsdist: Handle EAGAIN when reading from the non-blocking TCP pipe X-Git-Tag: dnsdist-1.4.0-alpha1~25^2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ea87ba72fee8701a240deb3ae0fa3e99df1a2e80;p=thirdparty%2Fpdns.git dnsdist: Handle EAGAIN when reading from the non-blocking TCP pipe --- diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 97ca4c73e0..ed9d896b5a 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -992,11 +992,18 @@ static void handleIncomingTCPQuery(int pipefd, FDMultiplexer::funcparam_t& param ConnectionInfo* citmp{nullptr}; - try { - readn2(pipefd, &citmp, sizeof(citmp)); + ssize_t got = read(pipefd, &citmp, sizeof(citmp)); + if (got == 0) { + throw std::runtime_error("EOF while reading from the TCP acceptor pipe (" + std::to_string(pipefd) + ") in " + std::string(isNonBlocking(pipefd) ? "non-blocking" : "blocking") + " mod"); + } + else if (got == -1) { + if (errno == EAGAIN || errno == EINTR) { + return; + } + throw std::runtime_error("Error while reading from the TCP acceptor pipe (" + std::to_string(pipefd) + ") in " + std::string(isNonBlocking(pipefd) ? "non-blocking" : "blocking") + " mde:" + strerror(errno)); } - 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()); + else if (got != sizeof(citmp)) { + throw std::runtime_error("Partial read while reading from the TCP acceptor pipe (" + std::to_string(pipefd) + ") in " + std::string(isNonBlocking(pipefd) ? "non-blocking" : "blocking") + " mode"); } g_tcpclientthreads->decrementQueuedCount();