]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: No need to retry if the last IO operation failed
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 10 Feb 2021 17:56:03 +0000 (18:56 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 2 Mar 2021 09:51:53 +0000 (10:51 +0100)
pdns/dnsdist-tcp.cc

index ee44e4025333234cc47851fb7db51bf2f34215de..f63f8b8f82d4b343dfeadde8e17d416951794cd7 100644 (file)
@@ -762,7 +762,7 @@ void IncomingTCPConnectionState::handleIO(std::shared_ptr<IncomingTCPConnectionS
         }
       }
 
-      if (state->d_state == IncomingTCPConnectionState::State::readingProxyProtocolHeader) {
+      if (!wouldBlock && state->d_state == IncomingTCPConnectionState::State::readingProxyProtocolHeader) {
         DEBUGLOG("reading proxy protocol header");
         do {
           iostate = state->d_handler.tryRead(state->d_buffer, state->d_currentPos, state->d_proxyProtocolNeed);
@@ -806,7 +806,7 @@ void IncomingTCPConnectionState::handleIO(std::shared_ptr<IncomingTCPConnectionS
         while (!wouldBlock);
       }
 
-      if (state->d_state == IncomingTCPConnectionState::State::readingQuerySize) {
+      if (!wouldBlock && state->d_state == IncomingTCPConnectionState::State::readingQuerySize) {
         DEBUGLOG("reading query size");
         iostate = state->d_handler.tryRead(state->d_buffer, state->d_currentPos, sizeof(uint16_t));
         if (iostate == IOState::Done) {
@@ -832,7 +832,7 @@ void IncomingTCPConnectionState::handleIO(std::shared_ptr<IncomingTCPConnectionS
         }
       }
 
-      if (state->d_state == IncomingTCPConnectionState::State::readingQuery) {
+      if (!wouldBlock && state->d_state == IncomingTCPConnectionState::State::readingQuery) {
         DEBUGLOG("reading query");
         iostate = state->d_handler.tryRead(state->d_buffer, state->d_currentPos, state->d_querySize);
         if (iostate == IOState::Done) {
@@ -858,15 +858,21 @@ void IncomingTCPConnectionState::handleIO(std::shared_ptr<IncomingTCPConnectionS
               ioGuard.release();
               state->d_state = IncomingTCPConnectionState::State::idle;
               iostate = sendResponse(state, now, std::move(resp));
+              if (iostate != IOState::Done) {
+                wouldBlock = true;
+              }
             }
           }
+          else if (iostate != IOState::Done) {
+            wouldBlock = true;
+          }
         }
         else {
           wouldBlock = true;
         }
       }
 
-      if (state->d_state == IncomingTCPConnectionState::State::sendingResponse) {
+      if (!wouldBlock && state->d_state == IncomingTCPConnectionState::State::sendingResponse) {
         DEBUGLOG("sending response");
         iostate = state->d_handler.tryWrite(state->d_currentResponse.d_buffer, state->d_currentPos, state->d_currentResponse.d_buffer.size());
         if (iostate == IOState::Done) {