Richard Zowalla created OPENNLP-1981:
----------------------------------------

             Summary: opennlp-dl pins the web application class loader and 
loads ONNX Runtime natives per class loader in application servers
                 Key: OPENNLP-1981
                 URL: https://issues.apache.org/jira/browse/OPENNLP-1981
             Project: OpenNLP
          Issue Type: Bug
            Reporter: Richard Zowalla
             Fix For: 3.0.0


Deploying opennlp\-dl with onnxruntime inside a web application 
\({{WEB\-INF/lib}}\) has these effects:
\* {{OrtEnvironment}} registers a JVM shutdown hook {{Thread}}. It is created 
on the thread that first calls {{AbstractDL}}, usually a request thread, so it 
captures that thread's context class loader and keeps the web application's 
class loader reachable until the JVM exits.
\* Every class loader that loads ONNX Runtime extracts and loads its own copy 
of the native libraries; they are not released on undeploy. With a shared 
{{onnxruntime.native.path}}, the second application fails with 
{{UnsatisfiedLinkError}} \(already loaded in another class loader\).
\* A native library that cannot be loaded surfaces from {{AbstractDL}} as 
{{ExceptionInInitializerError}} and then {{NoClassDefFoundError}}, which is not 
caught where {{OrtException}} is.

Suggested fix: set the context class loader to ONNX Runtime's class loader 
around the first ONNX Runtime call \(environment and session options creation\) 
and restore it afterwards; catch {{LinkageError}} and rethrow as 
{{IOException}}; document that onnxruntime and opennlp\-dl belong in the 
server's shared library.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to