]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Preserve caller context across Happy Eyeballs connection attempts (#499)
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Mon, 21 Oct 2019 21:32:18 +0000 (21:32 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Sun, 27 Oct 2019 11:25:38 +0000 (11:25 +0000)
To efficiently enforce various global and local limits, Happy Eyeballs
jobs uses two stand-alone HappyOrderEnforcer services that create job
calls. Thus, they need manual adjustments to preserve job context.

If similar changes are required in many places, we may want to add a
CodeContext member to the AsyncJob itself so that callbacks can
magically restore their context without service modifications (assuming
the job was created in or somehow provided the right context before
those callbacks).

src/HappyConnOpener.cc
src/HappyConnOpener.h

index bf40ceb55430b602fed160f439b73f3d09d3a59e..68bacbfd95ae700c72094895777e1b1c3cae3d25 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "squid.h"
 #include "AccessLogEntry.h"
+#include "base/CodeContext.h"
 #include "CachePeer.h"
 #include "errorpage.h"
 #include "FwdState.h"
@@ -152,6 +153,7 @@ HappyOrderEnforcer::enqueue(HappyConnOpener &job)
     Must(!job.spareWaiting.callback);
     jobs_.emplace_back(&job);
     job.spareWaiting.position = std::prev(jobs_.end());
+    job.spareWaiting.codeContext = CodeContext::Current();
 }
 
 void
@@ -172,10 +174,11 @@ HappyOrderEnforcer::checkpoint()
     while (!jobs_.empty()) {
         if (const auto jobPtr = jobs_.front().valid()) {
             auto &job = *jobPtr;
-            if (readyNow(job))
-                job.spareWaiting.callback = notify(jobPtr); // and fall through to the next job
-            else
+            if (!readyNow(job))
                 break; // the next job cannot be ready earlier (FIFO)
+            CallBack(job.spareWaiting.codeContext, [&] {
+                job.spareWaiting.callback = notify(jobPtr); // and fall through to the next job
+            });
         }
         jobs_.pop_front();
     }
index 7ba73f8a8b2e8ae6ac441dc809cd9f960450c836..a849b2b7e980a3d59bfb2ff02fd04de765cf364a 100644 (file)
@@ -38,6 +38,8 @@ public:
     /// nullifies but does not cancel the callback
     void clear() { *this = HappySpareWait(); }
 
+    CodeContext::Pointer codeContext; ///< requestor's context
+
     /// a pending noteGavePrimeItsChance() or noteSpareAllowance() call
     AsyncCall::Pointer callback;