]> granicus.if.org Git - pdns/commitdiff
dnsdist: Properly handle an I/O error while sending a TCP response
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 25 Mar 2019 16:10:13 +0000 (17:10 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 4 Apr 2019 09:54:04 +0000 (11:54 +0200)
pdns/dnsdist-tcp.cc

index ed9d896b5a103f6317ccbfda17dd4986102766e8..6a580a05ca3b0a3bba99b679a2231147dbb93293 100644 (file)
@@ -568,15 +568,21 @@ static void sendResponse(std::shared_ptr<IncomingTCPConnectionState>& 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 "<<state->d_ci.fd<<endl;
+      handleNewIOState(state, IOState::NeedWrite, state->d_ci.fd, handleIOCallback, state->getClientWriteTTD());
+    }
   }
-  else {
-    //cerr<<__func__<<": adding client write FD "<<state->d_ci.fd<<endl;
-    handleNewIOState(state, IOState::NeedWrite, state->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);
   }
 }