From: Remi Gacogne Date: Mon, 15 Jul 2019 08:28:01 +0000 (+0200) Subject: dnsdist: Catch exceptions thrown when handling a TCP response X-Git-Tag: dnsdist-1.4.0-rc1~47^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ffc95ec7b1b85d766f617e095e1a69096a5a2b4;p=pdns dnsdist: Catch exceptions thrown when handling a TCP response We need to handle it gracefully if a function called from handleResponse() throws, most likely because the answer received from the backend was not valid. --- diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index be50cd305..e49897902 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -968,7 +968,12 @@ static void handleDownstreamIO(std::shared_ptr& stat fd = -1; state->d_responseReadTime = now; - handleResponse(state, now); + try { + handleResponse(state, now); + } + catch (const std::exception& e) { + vinfolog("Got an exception while handling TCP response from %s (client is %s): %s", state->d_ds ? state->d_ds->getName() : "unknown", state->d_ci.remote.toStringWithPort(), e.what()); + } return; } } @@ -993,7 +998,7 @@ static void handleDownstreamIO(std::shared_ptr& stat } /* don't increase this counter when reusing connections */ - if (state->d_downstreamConnection->isFresh()) { + if (state->d_downstreamConnection && state->d_downstreamConnection->isFresh()) { ++state->d_downstreamFailures; } if (state->d_outstanding && state->d_ds != nullptr) {