diff --git a/flake.nix b/flake.nix index b2d670d..a91c177 100644 --- a/flake.nix +++ b/flake.nix @@ -86,6 +86,9 @@ "-Donnxruntime_BUILD_STATIC_LIB=ON" ]; }); + patchedOnnxruntime = pkgs.onnxruntime.overrideAttrs (old: { + patches = [./patches/ort_env_global_mutex.patch]; + }); src = let filterBySuffix = path: exts: lib.any (ext: lib.hasSuffix ext path) exts; sourceFilters = path: type: @@ -111,8 +114,8 @@ stdenv = p: p.clangStdenv; doCheck = false; LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; - ORT_LIB_LOCATION = "${pkgs.onnxruntime}"; - ORT_ENV_SYSTEM_LIB_LOCATION = "${pkgs.onnxruntime}/lib"; + ORT_LIB_LOCATION = "${patchedOnnxruntime}"; + ORT_ENV_SYSTEM_LIB_LOCATION = "${patchedOnnxruntime}/lib"; ORT_ENV_PREFER_DYNAMIC_LINK = true; nativeBuildInputs = with pkgs; [ cmake diff --git a/patches/ort_env_global_mutex.patch b/patches/ort_env_global_mutex.patch new file mode 100644 index 0000000..d53da86 --- /dev/null +++ b/patches/ort_env_global_mutex.patch @@ -0,0 +1,42 @@ +From 83e1dbf52b7695a2966795e0350aaa385d1ba8c8 Mon Sep 17 00:00:00 2001 +From: "Carson M." +Date: Sun, 22 Jun 2025 23:53:20 -0500 +Subject: [PATCH] Leak logger mutex + +--- + onnxruntime/core/common/logging/logging.cc | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/onnxruntime/core/common/logging/logging.cc b/onnxruntime/core/common/logging/logging.cc +index a79e7300cffce..07578fc72ca99 100644 +--- a/onnxruntime/core/common/logging/logging.cc ++++ b/onnxruntime/core/common/logging/logging.cc +@@ -64,8 +64,8 @@ LoggingManager* LoggingManager::GetDefaultInstance() { + #pragma warning(disable : 26426) + #endif + +-static std::mutex& DefaultLoggerMutex() noexcept { +- static std::mutex mutex; ++static std::mutex* DefaultLoggerMutex() noexcept { ++ static std::mutex* mutex = new std::mutex(); + return mutex; + } + +@@ -107,7 +107,7 @@ LoggingManager::LoggingManager(std::unique_ptr sink, Severity default_min + + // lock mutex to create instance, and enable logging + // this matches the mutex usage in Shutdown +- std::lock_guard guard(DefaultLoggerMutex()); ++ std::lock_guard guard(*DefaultLoggerMutex()); + + if (DefaultLoggerManagerInstance().load() != nullptr) { + ORT_THROW("Only one instance of LoggingManager created with InstanceType::Default can exist at any point in time."); +@@ -127,7 +127,7 @@ LoggingManager::LoggingManager(std::unique_ptr sink, Severity default_min + LoggingManager::~LoggingManager() { + if (owns_default_logger_) { + // lock mutex to reset DefaultLoggerManagerInstance() and free default logger from this instance. +- std::lock_guard guard(DefaultLoggerMutex()); ++ std::lock_guard guard(*DefaultLoggerMutex()); + #if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) + DefaultLoggerManagerInstance().store(nullptr, std::memory_order_release); + #else