]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Do not trigger warnings about orphaned PeerPoolMgr connections
authorAlex Rousskov <rousskov@measurement-factory.com>
Mon, 2 Aug 2021 02:26:05 +0000 (22:26 -0400)
committerAlex Rousskov <rousskov@measurement-factory.com>
Mon, 2 Aug 2021 02:27:42 +0000 (22:27 -0400)
... when PeerPoolMgr fails to start a Security::BlindPeerConnector job.

TODO: This should be handled via proper Connection-owning types instead
of explicit try/catch statements like this one.

src/PeerPoolMgr.cc
src/PeerPoolMgr.h

index bd950715d8cfa2f7078900f21f12a55b42529361..678fda0040f755025cef18120b3c03cabdb91135 100644 (file)
@@ -108,21 +108,34 @@ PeerPoolMgr::handleOpenedConnection(const CommConnectCbParams &params)
 
     // Handle TLS peers.
     if (peer->secure.encryptTransport) {
+        encryptTransport(params.conn);
+        return;
+    }
+
+    pushNewConnection(params.conn);
+}
+
+void
+PeerPoolMgr::encryptTransport(const Comm::ConnectionPointer &conn)
+{
+    try {
         AsyncCall::Pointer callback = asyncCall(48, 4, "PeerPoolMgr::handleSecuredPeer",
                                                 MyAnswerDialer(this, &PeerPoolMgr::handleSecuredPeer));
 
         const auto peerTimeout = peer->connectTimeout();
-        const int timeUsed = squid_curtime - params.conn->startTime();
+        const int timeUsed = squid_curtime - conn->startTime();
         // Use positive timeout when less than one second is left for conn.
         const int timeLeft = positiveTimeout(peerTimeout - timeUsed);
-        const auto connector = new Security::BlindPeerConnector(request, params.conn, callback, nullptr, timeLeft);
+        const auto connector = new Security::BlindPeerConnector(request, conn, callback, nullptr, timeLeft);
         encryptionWait.start(connector, callback);
         AsyncJob::Start(connector); // will call our callback
-        // XXX: Exceptions orphan params.conn
-        return;
     }
-
-    pushNewConnection(params.conn);
+    catch (...) {
+        conn->close();
+        // We could report and continue if we can recover from this failure, but
+        // it is difficult to determine/do that correctly so lets KISS for now.
+        throw;
+    }
 }
 
 void
index ae07c1fd1c9533fe0287f84e41516b2c03817b05..54af79973c93719982df8ca567aa686e0724e7c9 100644 (file)
@@ -52,6 +52,9 @@ protected:
     /// Comm::ConnOpener calls this when done opening a connection for us
     void handleOpenedConnection(const CommConnectCbParams &params);
 
+    /// initiates Security::PeerConnector work on a just-established connection
+    void encryptTransport(const Comm::ConnectionPointer &);
+
     /// Security::PeerConnector callback
     void handleSecuredPeer(Security::EncryptorAnswer &answer);