microsoft / microsoft/onnxruntime
[Mobile] calling synchronous methods on native modules is not supported in chrome.
@YUNQIUGUO is already working on this.
Since Nov 1, 2023.
- Dominant language
- C++
- Stars
- 21.9k
- Forks
- 4.2k
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 179
Description
Describe the issue
This is an issue that occurs when using the debugger during React Native development.
When in debug mode, there is code inserted at the following link indicating that synchronous methods are not supported: (https://github.com/facebook/react-native/blob/817fedb0e7a5276d86431c65cc886062ed8fe220/packages/react-native/Libraries/BatchedBridge/MessageQueue.js#L175)
Upon my investigation, I have confirmed that the issue arises from the following code:
OnnxruntimeJSIHelper.install();
https://github.com/microsoft/onnxruntime/blob/2b95e74fa113ec168a79974987b2c6b98cecf700/js/react_native/lib/binding.ts#L85
When this code is used, an error occurs, stating calling synchronous methods on native modules is not supported in chrome.
I have also observed that the install method is implemented as follows: https://github.com/microsoft/onnxruntime/blob/2b95e74fa113ec168a79974987b2c6b98cecf700/js/react_native/android/src/main/java/ai/onnxruntime/reactnative/OnnxruntimeJSIHelper.java#L38
It seems that it should be implemented as an asynchronous method to be compatible with the React Native debugger.
To reproduce
The code I used for reproduce is as follows:
import * as ort from 'onnxruntime-react-native';
...
static async init(onnx) {
try {
const asset = ReactNativeBlobUtil.fs.asset(path.resolve('custom', onnx));
const cache = path.resolve(ReactNativeBlobUtil.fs.dirs.CacheDir, onnx);
await ReactNativeBlobUtil.fs.cp(asset, cache);
const session = await ort.InferenceSession.create('file://' + cache);
return new this(session);
} catch (error) {
console.error(error);
throw error;
}
}
When executing the line const session = await ort.InferenceSession.create('file://' + cache); in the code, the error message mentioned earlier, calling synchronous methods on native modules is not supported in chrome is displayed.
This error appears to occur in accordance with the description provided above.
It is essential to be using the Remote debugger for reproducing the issue. The problem does not manifest when the Remote debugger is not in use.
Urgency
No response
Platform
React Native
OS Version
android version 13
ONNX Runtime Installation
Released Package
Compiler Version (if 'Built from Source')
No response
Package Name (if 'Released Package')
onnxruntime-react-native
ONNX Runtime Version or Commit ID
1.16.1
ONNX Runtime API
JavaScript
Architecture
X64
Execution Provider
Other / Unknown
Execution Provider Library Version
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.