]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Preserve caller context across IPC-related timeout events (#742)
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Tue, 27 Oct 2020 06:16:59 +0000 (06:16 +0000)
committerAmos Jeffries <yadij@users.noreply.github.com>
Sun, 8 Nov 2020 04:12:20 +0000 (17:12 +1300)
Before this fix, the transaction context was not saved/restored when
scheduling the following three events:

* Ipc::Forwarder::RequestTimedOut()
* Ipc::UdsSender::DelayedRetry()
* Ipc::Inquirer::RequestTimedOut()

src/ipc/Forwarder.cc
src/ipc/Forwarder.h
src/ipc/Inquirer.cc
src/ipc/Inquirer.h
src/ipc/UdsOp.cc
src/ipc/UdsOp.h

index f696b45e4a879df9f9bd7a9dbd798ca029e812a9..70ec73a7b8fee37cf39acb0be209658d9ad59610 100644 (file)
@@ -25,6 +25,7 @@ unsigned int Ipc::Forwarder::LastRequestId = 0;
 
 Ipc::Forwarder::Forwarder(Request::Pointer aRequest, double aTimeout):
     AsyncJob("Ipc::Forwarder"),
+    codeContext(CodeContext::Current()),
     request(aRequest), timeout(aTimeout)
 {
 }
@@ -101,7 +102,10 @@ Ipc::Forwarder::RequestTimedOut(void* param)
     Must(param != NULL);
     Forwarder* fwdr = static_cast<Forwarder*>(param);
     // use async call to enable job call protection that time events lack
-    CallJobHere(54, 5, fwdr, Forwarder, requestTimedOut);
+
+    CallBack(fwdr->codeContext, [&fwdr] {
+        CallJobHere(54, 5, fwdr, Forwarder, requestTimedOut);
+    });
 }
 
 /// called when Coordinator fails to start processing the request [in time]
index 03acb4ae57d03479c119cf3ea1b30a64434f711f..69c957b773eee1f6b821dfe7c15bf6760864f845 100644 (file)
@@ -12,6 +12,7 @@
 #define SQUID_IPC_FORWARDER_H
 
 #include "base/AsyncJob.h"
+#include "base/forward.h"
 #include "cbdata.h"
 #include "ipc/Request.h"
 #include "mgr/ActionParams.h"
@@ -39,6 +40,8 @@ public:
     /* has-to-be-public AsyncJob API */
     virtual void callException(const std::exception& e);
 
+    CodeContextPointer codeContext;
+
 protected:
     /* AsyncJob API */
     virtual void start();
index c4705c46bda21445a13d9b0082e505efbfb467e9..6ce807ce3f07a73e062895856c275a913eaed8b8 100644 (file)
@@ -33,6 +33,7 @@ LesserStrandByKidId(const Ipc::StrandCoord &c1, const Ipc::StrandCoord &c2)
 Ipc::Inquirer::Inquirer(Request::Pointer aRequest, const StrandCoords& coords,
                         double aTimeout):
     AsyncJob("Ipc::Inquirer"),
+    codeContext(CodeContext::Current()),
     request(aRequest), strands(coords), pos(strands.begin()), timeout(aTimeout)
 {
     debugs(54, 5, HERE);
@@ -181,7 +182,9 @@ Ipc::Inquirer::RequestTimedOut(void* param)
     Must(param != NULL);
     Inquirer* cmi = static_cast<Inquirer*>(param);
     // use async call to enable job call protection that time events lack
-    CallJobHere(54, 5, cmi, Inquirer, requestTimedOut);
+    CallBack(cmi->codeContext, [&cmi] {
+        CallJobHere(54, 5, cmi, Inquirer, requestTimedOut);
+    });
 }
 
 /// called when the strand failed to respond (or finish responding) in time
index f1e3fad49619b8ed6aaf8571eb7fb3c35c2ab341..527252aa601ce82e9f76820b7f93f4cc7353eed6 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "base/AsyncJob.h"
 #include "base/AsyncJobCalls.h"
+#include "base/forward.h"
 #include "ipc/forward.h"
 #include "ipc/Request.h"
 #include "ipc/Response.h"
@@ -38,6 +39,8 @@ public:
     /* has-to-be-public AsyncJob API */
     virtual void callException(const std::exception& e);
 
+    CodeContextPointer codeContext;
+
 protected:
     /* AsyncJob API */
     virtual void start();
index 726443ade05204f85c2b64fecfae1d7838592bbc..a6ba254693983342b76d2654b305dda2f9bf234e 100644 (file)
@@ -83,6 +83,7 @@ CBDATA_NAMESPACED_CLASS_INIT(Ipc, UdsSender);
 
 Ipc::UdsSender::UdsSender(const String& pathAddr, const TypedMsgHdr& aMessage):
     UdsOp(pathAddr),
+    codeContext(CodeContext::Current()),
     message(aMessage),
     retries(10), // TODO: make configurable?
     timeout(10), // TODO: make configurable?
@@ -161,10 +162,9 @@ void Ipc::UdsSender::DelayedRetry(void *data)
     Pointer *ptr = static_cast<Pointer*>(data);
     assert(ptr);
     if (UdsSender *us = dynamic_cast<UdsSender*>(ptr->valid())) {
-        // get back inside AsyncJob protection by scheduling an async job call
-        typedef NullaryMemFunT<Ipc::UdsSender> Dialer;
-        AsyncCall::Pointer call = JobCallback(54, 4, Dialer, us, Ipc::UdsSender::delayedRetry);
-        ScheduleCallHere(call);
+        CallBack(us->codeContext, [&us] {
+            CallJobHere(54, 4, us, UdsSender, delayedRetry);
+        });
     }
     delete ptr;
 }
index 84f83212479b7f3787a64413c9fb4ff2831eae1a..54bc13fd29fd83f633fc95644b97e2f7ffafc358 100644 (file)
@@ -12,6 +12,7 @@
 #define SQUID_IPC_ASYNCUDSOP_H
 
 #include "base/AsyncJob.h"
+#include "base/forward.h"
 #include "cbdata.h"
 #include "comm/forward.h"
 #include "ipc/FdNotes.h"
@@ -71,6 +72,8 @@ class UdsSender: public UdsOp
 public:
     UdsSender(const String& pathAddr, const TypedMsgHdr& aMessage);
 
+    CodeContextPointer codeContext;
+
 protected:
     virtual void swanSong(); // UdsOp (AsyncJob) API
     virtual void start(); // UdsOp (AsyncJob) API