-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Mobile][Android][Bug] SIGSEGV if ortSession.close() is called before ortSession.run() finish #21812
Comments
After a night of sleep, i realized that my request is technically hard and not really in concordance with the structure of onnxruntime. The only way to do this is to make run() be executed in a new thread internally that can be forcefully closed, but i suppose that onnxruntime structure wants to leave the threading management to the end developer and not be managed internally (i agree with this). Worst case scenario the dev can close it's own thread forcefully (not recommended of course, by any good development practice) or make some GUI adjustements. Still, it would be nice to have a clarification in the documentation, that ortSession.close() doesn't prevent this, is not really clear, as i assumed that close() would stop run() if it was executing it. my 2 cents. |
If you need to abort an inference then you should supply a We can make the documentation modification, and I am interested in the case where calling terminate prevents you from creating a new session, because that sounds like a bug somewhere. |
Thanks for the answer. Answering, i passed RunOptions with setTermine(true) on the new created ortSession.run() just ends with an exception that the inerence ended (but doesn't crash). I'll create and submit a test project to reproduce. |
The exception is the only way that call can end so at the moment you need to catch it and special case the handling logic to check if it's from the terminate flag (e.g. https://github.com/microsoft/onnxruntime/blob/main/java/src/test/java/ai/onnxruntime/InferenceTest.java#L1214), but I agree it would be nicer to have it be a subclass of |
Describe the issue
It took me a while to figure out why the testing in the store keep crashing, until i found this.
If ortSession.close() is called before ortSession.run() finish it causes a SIGSEGV on the next ortSession.run().
This happen even if you nullify the ortSession and create a new one with a diferent model.
Passing RunOption.setTerminate(true) to run() prevents the crashing, but doesn't allow to run any other future ineference.
ortSession.close should somehow, forcefully close the run(), or have a new method to stop the run(), in case the user wants to abort the operation, if not, devs are forced to make the user wait until the whole ineference finish to abort the operation.
Of course, i understand i'm destroying an or closing an object when another thread and operation is using it, but that why one of this functions are needed.
To reproduce
Urgency
Is pretty urgent as it blocks the user experience having to wait until the ineference finish, to cancel the operation.
Platform
Android
OS Version
14
ONNX Runtime Installation
Built from Source
Compiler Version (if 'Built from Source')
34
Package Name (if 'Released Package')
onnxruntime-android
ONNX Runtime Version or Commit ID
1.20.0
ONNX Runtime API
Java/Kotlin
Architecture
ARM64
Execution Provider
Default CPU
Execution Provider Library Version
No response
The text was updated successfully, but these errors were encountered: