Richard Zowalla created OPENNLP-1976:
----------------------------------------

             Summary: AbstractDL.close() does not wait for in-flight inference, 
so a concurrent close can free the native session during a run
                 Key: OPENNLP-1976
                 URL: https://issues.apache.org/jira/browse/OPENNLP-1976
             Project: OpenNLP
          Issue Type: Bug
            Reporter: Richard Zowalla
             Fix For: 3.0.0


{{AbstractDL.close\(\)}} only guards against a second close \({{AtomicBoolean}} 
compare\-and\-set\) and then calls {{OrtSession.close\(\)}}. It does not wait 
for {{session.run}} calls that are still executing in {{SentenceVectorsDL}}, 
{{NameFinderDL}} or {{DocumentCategorizerDL}}. In ONNX Runtime Java, 
{{OrtSession.closed}} is a plain boolean checked before the native call, so a 
run that overlaps {{close\(\)}} can execute on a freed native session. The 
result is undefined native behavior, up to a JVM crash, rather than an 
exception. This happens in practice when an application server undeploys an 
application while requests are still being served.

Suggested fix: guard every {{session.run}} with a read lock \(or an in\-flight 
counter\) in a protected helper of {{AbstractDL}}, take the write lock in 
{{close\(\)}}, and throw {{IllegalStateException}} for calls after close. If 
in\-flight runs do not finish within a bounded time, log and skip freeing the 
session instead of freeing it under a running call.



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

Reply via email to