From d7aff6e65a65bcafd204257535fac5827b3f162b Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 11 Mar 2019 12:21:18 +0100 Subject: [PATCH] dnsdist: Handle EAGAIN in the GnuTLS DNS over TLS provider --- pdns/dnsdistdist/tcpiohandler.cc | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pdns/dnsdistdist/tcpiohandler.cc b/pdns/dnsdistdist/tcpiohandler.cc index 1f516f14f..2be4a4c62 100644 --- a/pdns/dnsdistdist/tcpiohandler.cc +++ b/pdns/dnsdistdist/tcpiohandler.cc @@ -712,9 +712,17 @@ public: } else if (res < 0) { if (gnutls_error_is_fatal(res)) { - throw std::runtime_error("Error reading from TLS connection"); + throw std::runtime_error("Error reading from TLS connection:" + std::string(gnutls_strerror(res))); + } + else if (res == GNUTLS_E_AGAIN) { + int result = waitForData(d_socket, readTimeout); + if (result <= 0) { + throw std::runtime_error("Error reading from TLS connection: " + std::to_string(result)); + } + } + else { + vinfolog("Non-fatal error while reading from TLS connection: %s", gnutls_strerror(res)); } - warnlog("Warning, non-fatal error while reading from TLS connection: %s", gnutls_strerror(res)); } if (totalTimeout) { @@ -746,9 +754,17 @@ public: } else if (res < 0) { if (gnutls_error_is_fatal(res)) { - throw std::runtime_error("Error writing to TLS connection"); + throw std::runtime_error("Error writing to TLS connection: " + std::string(gnutls_strerror(res))); + } + else if (res == GNUTLS_E_AGAIN) { + int result = waitForRWData(d_socket, false, writeTimeout, 0); + if (result <= 0) { + throw std::runtime_error("Error waiting to write to TLS connection: " + std::to_string(result)); + } + } + else { + vinfolog("Non-fatal error while writing to TLS connection: %s", gnutls_strerror(res)); } - warnlog("Warning, non-fatal error while writing to TLS connection: %s", gnutls_strerror(res)); } } while (got < bufferSize); -- 2.40.0