From: Remi Gacogne Date: Mon, 15 Feb 2021 14:45:58 +0000 (+0100) Subject: dnsdist: Send a TCP query to the backend if we are not reading an answer X-Git-Tag: dnsdist-1.6.0-alpha2~11^2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3e4e53e6e657b36bb6619b82e0e0695e2cb8388;p=thirdparty%2Fpdns.git dnsdist: Send a TCP query to the backend if we are not reading an answer --- diff --git a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc index 2f9ffbf862..74f5fe46f7 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc +++ b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc @@ -99,14 +99,15 @@ void TCPConnectionToBackend::handleIO(std::shared_ptr& c } if (iostate == IOState::Done && conn->d_pendingQueries.empty()) { - conn->d_state = State::readingResponseSizeFromBackend; + conn->d_state = State::waitingForResponseFromBackend; conn->d_currentPos = 0; conn->d_responseBuffer.resize(sizeof(uint16_t)); iostate = IOState::NeedRead; } } - if (conn->d_state == State::readingResponseSizeFromBackend) { + if (conn->d_state == State::waitingForResponseFromBackend || + conn->d_state == State::readingResponseSizeFromBackend) { DEBUGLOG("reading response size from backend"); // then we need to allocate a new buffer (new because we might need to re-send the query if the // backend dies on us) @@ -121,6 +122,9 @@ void TCPConnectionToBackend::handleIO(std::shared_ptr& c conn->d_responseBuffer.resize(conn->d_responseSize); conn->d_currentPos = 0; } + else if (conn->d_state == State::waitingForResponseFromBackend && conn->d_currentPos > 0) { + conn->d_state = State::readingResponseSizeFromBackend; + } } if (conn->d_state == State::readingResponseFromBackend) { @@ -142,6 +146,7 @@ void TCPConnectionToBackend::handleIO(std::shared_ptr& c if (conn->d_state != State::idle && conn->d_state != State::sendingQueryToBackend && + conn->d_state != State::waitingForResponseFromBackend && conn->d_state != State::readingResponseSizeFromBackend && conn->d_state != State::readingResponseFromBackend) { vinfolog("Unexpected state %d in TCPConnectionToBackend::handleIO", static_cast(conn->d_state)); @@ -264,7 +269,7 @@ void TCPConnectionToBackend::queueQuery(TCPQuery&& query, std::shared_ptrupdate(IOState::NeedWrite, handleIOCallback, sharedSelf, getBackendWriteTTD(now)); } else { + DEBUGLOG("Adding new query to the queue because we are in state "<<(int)d_state); // store query in the list of queries to send d_pendingQueries.push_back(std::move(query)); } @@ -427,7 +433,7 @@ IOState TCPConnectionToBackend::handleResponse(std::shared_ptrhandleXFRResponse(clientConn, now, std::move(response)); - d_state = State::readingResponseSizeFromBackend; + d_state = State::waitingForResponseFromBackend; d_currentPos = 0; d_responseBuffer.resize(sizeof(uint16_t)); // get ready to read the next packet, if any @@ -474,7 +480,7 @@ IOState TCPConnectionToBackend::handleResponse(std::shared_ptr