From 0ffc95ec7b1b85d766f617e095e1a69096a5a2b4 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 15 Jul 2019 10:28:01 +0200 Subject: [PATCH] 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. --- pdns/dnsdist-tcp.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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) { -- 2.40.0