From ea87ba72fee8701a240deb3ae0fa3e99df1a2e80 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 21 Mar 2019 18:49:27 +0100 Subject: [PATCH] dnsdist: Handle EAGAIN when reading from the non-blocking TCP pipe --- pdns/dnsdist-tcp.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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(); -- 2.47.3