]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
wip for acquire/release in broadcast pipes
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 18 Dec 2025 14:33:02 +0000 (15:33 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 18 Dec 2025 15:08:11 +0000 (16:08 +0100)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/recursordist/rec-main.cc
regression-tests.api/runtests.py

index 3811b9ebd9b49a267e9d577670463fec4b83b8b8..749078e467814bb2428640d8789ed42b1225d366 100644 (file)
@@ -81,6 +81,24 @@ thread_local FrameStreamServersInfo t_nodFrameStreamServersInfo;
 #endif
 #endif
 
+#if __SANITIZE_THREAD__
+#if defined __has_include
+#if __has_include(<sanitizer/tsan_interface.h>)
+#include <sanitizer/tsan_interface.h>
+#else /* __has_include(<sanitizer/tsan_interface.h>) */
+extern "C" void __tsan_acquire(void* addr);
+extern "C" void __tsan_release(void* addr);
+#endif /* __has_include(<sanitizer/tsan_interface.h>) */
+#else /* defined __has_include */
+extern "C" void __tsan_acquire(void* addr);
+extern "C" void __tsan_release(void* addr);
+#endif /* defined __has_include */
+#else
+#error XXXX
+#define __tsan_acquire(x)
+#define __tsan_release(x)
+#endif /* __SANITIZE_THREAD__ */
+
 string g_programname = "pdns_recursor";
 string g_pidfname;
 RecursorControlChannel g_rcc; // only active in the handler thread
@@ -1507,7 +1525,13 @@ void broadcastFunction(const pipefunc_t& func)
     ThreadMSG* tmsg = new ThreadMSG(); // NOLINT: manual ownership handling
     tmsg->func = func;
     tmsg->wantAnswer = true;
+
+      __tsan_release(tmsg);
+
     if (write(threadInfo.getPipes().writeToThread, &tmsg, sizeof(tmsg)) != sizeof(tmsg)) { // NOLINT: sizeof correct
+
+      __tsan_acquire(tmsg);
+
       delete tmsg; // NOLINT: manual ownership handling
 
       unixDie("write to thread pipe returned wrong size or error");
@@ -1518,6 +1542,8 @@ void broadcastFunction(const pipefunc_t& func)
       unixDie("read from thread pipe returned wrong size or error");
     }
 
+    __tsan_acquire(resp);
+
     if (resp != nullptr) {
       delete resp; // NOLINT: manual ownership handling
       resp = nullptr;
@@ -1588,7 +1614,12 @@ T broadcastAccFunction(const std::function<T*()>& func)
     tmsg->func = [func] { return voider<T>(func); };
     tmsg->wantAnswer = true;
 
+    __tsan_release(tmsg);
+
     if (write(tps.writeToThread, &tmsg, sizeof(tmsg)) != sizeof(tmsg)) { // NOLINT:: sizeof correct
+
+      __tsan_acquire(tmsg);
+
       delete tmsg; // NOLINT: manual ownership handling
       unixDie("write to thread pipe returned wrong size or error");
     }
@@ -1597,6 +1628,8 @@ T broadcastAccFunction(const std::function<T*()>& func)
     if (read(tps.readFromThread, &resp, sizeof(resp)) != sizeof(resp)) // NOLINT: sizeof correct
       unixDie("read from thread pipe returned wrong size or error");
 
+    __tsan_acquire(resp);
+
     if (resp) {
       ret += *resp;
       delete resp; // NOLINT: manual ownership handling
@@ -2353,6 +2386,8 @@ static void handlePipeRequest(int fileDesc, FDMultiplexer::funcparam_t& /* var *
     unixDie("read from thread pipe returned wrong size or error");
   }
 
+   __tsan_acquire(tmsg);
+
   void* resp = nullptr;
   try {
     resp = tmsg->func();
@@ -2372,6 +2407,9 @@ static void handlePipeRequest(int fileDesc, FDMultiplexer::funcparam_t& /* var *
     g_rateLimitedLogger.log(g_slog->withName("runtime"), "PIPE function");
   }
   if (tmsg->wantAnswer) {
+
+   __tsan_release(resp);
+
     if (write(RecThreadInfo::self().getPipes().writeFromThread, &resp, sizeof(resp)) != sizeof(resp)) {
       delete tmsg; // NOLINT: manual ownership handling
       unixDie("write to thread pipe returned wrong size or error");
index cb9bcdea1592213a32150c834b5f447ec2d3b92b..8fd736450c4f9c2afb5b465857febeaf6fe5a16d 100755 (executable)
@@ -161,7 +161,7 @@ if daemon not in ('authoritative', 'recursor') or backend not in ('gmysql', 'gpg
 daemon = sys.argv[1]
 
 pdns_server = os.environ.get("PDNSSERVER", "../pdns/pdns_server")
-pdns_recursor = os.environ.get("PDNSRECURSOR", "../pdns/recursordist/pdns_recursor")
+pdns_recursor = os.environ.get("PDNSRECURSOR", "../pdns/recursordist/build/pdns_recursor")
 common_args = [
     "--daemon=no", "--socket-dir=.", "--config-dir=.",
     "--local-address=127.0.0.1", "--local-port="+str(DNSPORT),