]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Release failed TCP backend connections more quickly 14004/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 29 Mar 2024 14:08:29 +0000 (15:08 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 29 Mar 2024 14:12:03 +0000 (15:12 +0100)
After a timeout we cannot reuse the TCP connection to the backend
anyway, so let's release it immediately.

pdns/dnsdistdist/dnsdist-tcp-downstream.cc
pdns/dnsdistdist/test-dnsdisttcp_cc.cc

index 684c46fceee1913ff9aeaf004b32366b50805e41..e72d9ac180d39e99265a3f9055dc57f369b3afb5 100644 (file)
@@ -146,6 +146,13 @@ void TCPConnectionToBackend::release(){
   if (d_ioState) {
     d_ioState.reset();
   }
+
+  auto shared = std::dynamic_pointer_cast<TCPConnectionToBackend>(shared_from_this());
+  if (!willBeReusable(true)) {
+    /* remove ourselves from the connection cache, this might mean that our
+       reference count drops to zero after that, so we need to be careful */
+    t_downstreamTCPConnectionsManager.removeDownstreamConnection(shared);
+  }
 }
 
 static uint32_t getSerialFromRawSOAContent(const std::vector<uint8_t>& raw)
index 3566d61c5096849cb9b64e13f6926fad202091fc..a27029361b5f10366a012f18cb7eb5776c96148d 100644 (file)
@@ -3620,8 +3620,8 @@ BOOST_FIXTURE_TEST_CASE(test_IncomingConnectionOOOR_BackendOOOR, TestFixture)
     g_tcpRecvTimeout = 2;
 
     /* we need to clear them now, otherwise we end up with dangling pointers to the steps via the TLS context, etc */
-    /* we have one connection to clear, no proxy protocol */
-    BOOST_CHECK_EQUAL(IncomingTCPConnectionState::clearAllDownstreamConnections(), 1U);
+    /* we have no connection to clear, because there was a timeout! */
+    BOOST_CHECK_EQUAL(IncomingTCPConnectionState::clearAllDownstreamConnections(), 0U);
   }
 
   {