]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
luawrapper: on luajit+arm64+tsan, retry allocs harder 16451/head
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Fri, 7 Nov 2025 16:01:03 +0000 (17:01 +0100)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Mon, 10 Nov 2025 10:23:58 +0000 (11:23 +0100)
Co-authored-by: Miod Vallat <miod.vallat@powerdns.com>
Co-authored-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
Signed-off-by: Peter van Dijk <peter.van.dijk@powerdns.com>
ext/luawrapper/include/LuaContext.hpp

index 2284e44922bfdcfae74f518110257fa55da5dc1f..95192586d6d8aa58ad8ee383607d29eaba852556 100644 (file)
@@ -56,6 +56,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <boost/type_traits.hpp>
 #include <lua.hpp>
 
+// Set the older gcc define for tsan if clang or modern gcc tell us we have tsan.
+#if defined(__has_feature)
+#if __has_feature(thread_sanitizer)
+#define __SANITIZE_THREAD__ 1
+#endif
+#endif
+
 #if defined(_MSC_VER) && _MSC_VER < 1900
 #   include "misc/exception.hpp"
 #endif
@@ -98,7 +105,17 @@ public:
     explicit LuaContext(bool openDefaultLibs = true)
     {
         // luaL_newstate can return null if allocation failed
-        mState = luaL_newstate();
+#if defined(__SANITIZE_THREAD__) && defined(LUAJIT_VERSION) && defined(__aarch64__)
+        // on arm64 with luajit and TSAN, allocation may fail spuriously, so keep retrying a bit
+        int tries = 100;
+#else
+        int tries = 1;
+#endif
+        for (; tries > 0; tries--) {
+          mState = luaL_newstate();
+          if (mState != nullptr) { break; }
+        }
+#undef RETRIES
         if (mState == nullptr)
             throw std::bad_alloc();