From d78a50820ecbaa4cd07fc607dbb911ddc224463b Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Thu, 5 May 2022 22:50:44 +0000 Subject: [PATCH] Fix OrtEnv creation causing server to hang during shutdown. OrtEnv gets created twice in onnx_loader. This causes its refcount to increase to 2. Due to this when ReleaseEnv is called inside ~OnnxLoader, it does nothing other than decrease the refcount to 1. Next all the libraries are unloaded the openvino global context ptr gets unloaded followed by OrtEnv's destructor which now actually does useful work trying to delete the openvno ctx ptr which is not valid any more causing memory corruption. --- src/onnxruntime_loader.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/onnxruntime_loader.cc b/src/onnxruntime_loader.cc index 0f81124..1b36813 100644 --- a/src/onnxruntime_loader.cc +++ b/src/onnxruntime_loader.cc @@ -31,6 +31,7 @@ #include #include #include + #include "onnxruntime_utils.h" namespace triton { namespace backend { namespace onnxruntime { @@ -55,9 +56,9 @@ OnnxLoader::Init(common::TritonJson::Value& backend_config) OrtLoggingLevel logging_level = TRITONSERVER_LogIsEnabled(TRITONSERVER_LOG_VERBOSE) ? ORT_LOGGING_LEVEL_VERBOSE - : TRITONSERVER_LogIsEnabled(TRITONSERVER_LOG_WARN) - ? ORT_LOGGING_LEVEL_WARNING - : ORT_LOGGING_LEVEL_ERROR; + : TRITONSERVER_LogIsEnabled(TRITONSERVER_LOG_WARN) + ? ORT_LOGGING_LEVEL_WARNING + : ORT_LOGGING_LEVEL_ERROR; // Controls whether to enable global threadpool which will be shared across // sessions. Use this in conjunction with DisablePerSessionThreads API or @@ -110,7 +111,6 @@ OnnxLoader::Init(common::TritonJson::Value& backend_config) status = ort_api->CreateEnv(logging_level, "log", &env); } - status = ort_api->CreateEnv(logging_level, "log", &env); loader.reset(new OnnxLoader(env, global_threadpool_enabled)); RETURN_IF_ORT_ERROR(status); } else {