]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix Tunneler handling of last-resort callback requirements
authorAlex Rousskov <rousskov@measurement-factory.com>
Wed, 14 Jul 2021 20:58:10 +0000 (16:58 -0400)
committerAlex Rousskov <rousskov@measurement-factory.com>
Fri, 16 Jul 2021 17:33:09 +0000 (13:33 -0400)
... and simplify the corresponding code.

Events like noteAbort() and callException() terminate the job but are
not bugs that should be reported by swanSong().

Not treating (rare) cancelled callbacks specially in swanSong() allows
us to avoid making cleanup code even more complex than it already is,
undoing branch changes that introduced closeQuietly().

src/clients/HttpTunneler.cc
src/clients/HttpTunneler.h

index 3ae727bda124825ca63d8e60a811ff55541601d3..f4ceb2d2e8ebbcff7aaeda3e102f6f9740baec39 100644 (file)
@@ -364,14 +364,8 @@ Http::Tunneler::bailWith(ErrorState *error)
         peerConnectFailed(p);
 
     callBack();
-
-    closeQuietly();
-}
-
-void
-Http::Tunneler::closeQuietly()
-{
     disconnect();
+
     if (noteFwdPconnUse)
         fwdPconnPool->noteUses(fd_table[connection->fd].pconn.uses);
     // TODO: Reuse to-peer connections after a CONNECT error response.
@@ -421,19 +415,13 @@ Http::Tunneler::swanSong()
     AsyncJob::swanSong();
 
     if (callback) {
-        if (callback->canceled()) {
-            debugs(83, 3, "cancelled by the caller");
-            closeQuietly();
+        if (requestWritten && tunnelEstablished) {
+            sendSuccess();
         } else {
-            if (requestWritten && tunnelEstablished) {
-                sendSuccess();
-            } else {
-                // we should have bailed when we discovered the job-killing problem
-                debugs(83, DBG_IMPORTANT, "BUG: Unexpected state while establishing a CONNECT tunnel " << connection << status());
-                bailWith(new ErrorState(ERR_GATEWAY_FAILURE, Http::scInternalServerError, request.getRaw(), al));
-            }
-            assert(!callback);
+            // job-ending emergencies like noteAbort() or callException()
+            bailWith(new ErrorState(ERR_GATEWAY_FAILURE, Http::scInternalServerError, request.getRaw(), al));
         }
+        assert(!callback);
     }
 }
 
index 00f9228c5f837d65569799a8fc334f95ccc85ac7..08803eed999070e1d26fb493e72aa67076535d34 100644 (file)
@@ -34,8 +34,6 @@ class Tunneler: virtual public AsyncJob
     CBDATA_CLASS(Tunneler);
 
 public:
-    typedef CbcPointer<Tunneler> Pointer;
-
     /// Callback dialer API to allow Tunneler to set the answer.
     template <class Initiator>
     class CbDialer: public CallDialer, public Http::TunnelerAnswer
@@ -104,8 +102,6 @@ protected:
     TunnelerAnswer &answer();
 
 private:
-    void closeQuietly();
-
     AsyncCall::Pointer writer; ///< called when the request has been written
     AsyncCall::Pointer reader; ///< called when the response should be read
     AsyncCall::Pointer closer; ///< called when the connection is being closed