From: Remi Gacogne Date: Mon, 25 Mar 2019 16:10:13 +0000 (+0100) Subject: dnsdist: Properly handle an I/O error while sending a TCP response X-Git-Tag: dnsdist-1.4.0-alpha1~25^2~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2f1f96b08b71ac61bb327a104093196a3744da63;p=pdns dnsdist: Properly handle an I/O error while sending a TCP response --- diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index ed9d896b5..6a580a05c 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -568,15 +568,21 @@ static void sendResponse(std::shared_ptr& state) state->d_currentPos = 0; - auto iostate = state->d_handler.tryWrite(state->d_responseBuffer, state->d_currentPos, state->d_responseBuffer.size()); - if (iostate == IOState::Done) { + try { + auto iostate = state->d_handler.tryWrite(state->d_responseBuffer, state->d_currentPos, state->d_responseBuffer.size()); + if (iostate == IOState::Done) { - handleResponseSent(state); - return; + handleResponseSent(state); + return; + } + else { + //cerr<<__func__<<": adding client write FD "<d_ci.fd<d_ci.fd, handleIOCallback, state->getClientWriteTTD()); + } } - else { - //cerr<<__func__<<": adding client write FD "<d_ci.fd<d_ci.fd, handleIOCallback, state->getClientWriteTTD()); + catch (const std::exception& e) { + vinfolog("Got an exception while writing TCP response to %s: %s", state->d_ci.remote.toStringWithPort(), e.what()); + handleNewIOState(state, IOState::Done, state->d_ci.fd, handleIOCallback); } }