From: Eduard Bagdasaryan Date: Mon, 21 Oct 2019 21:32:18 +0000 (+0000) Subject: Preserve caller context across Happy Eyeballs connection attempts (#499) X-Git-Tag: SQUID_5_0_1~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=99ecc6a434d3f241fdb11133537a68b306bc8a59;p=thirdparty%2Fsquid.git Preserve caller context across Happy Eyeballs connection attempts (#499) 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). --- diff --git a/src/HappyConnOpener.cc b/src/HappyConnOpener.cc index bf40ceb554..68bacbfd95 100644 --- a/src/HappyConnOpener.cc +++ b/src/HappyConnOpener.cc @@ -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(); } diff --git a/src/HappyConnOpener.h b/src/HappyConnOpener.h index 7ba73f8a8b..a849b2b7e9 100644 --- a/src/HappyConnOpener.h +++ b/src/HappyConnOpener.h @@ -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;