-
Notifications
You must be signed in to change notification settings - Fork 647
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
random crash when reload with two or more simple jsi modules on ios #1011
Comments
Hi, as you can see from the screen shot you provided, this is a deliberate diagnostic crash indicating that a Hermes runtime is used simultaneously from two separate threads without synchronization. JSI is not a thread-safe API, as is explained in this comment: Line 154 in 869312f
So, the problem is that the application is using JSI from multiple threads without proper synchronization. |
Both those modules themselves do not use multithreading and do not add any js code in demo app to call the methods in the jsi modules, just crash when the app launch or reload (loads the jsi module), so the problem should be a hermes jsi problem or react-native problem? Including the following issue #facebook/react-native#35720 (comment), which seems to be a common problem? Should it be solved from the architecture? Or is there a general generic template code that provides the correct code to initialize jsi module to avoid similar problems? |
@iwater can you generate a text dump of all thread stacks at the moment of the crash? |
|
There is something fishy going on between thread 1 and thread 15. Seems like thread 15 is destroying the runtime while thread 1 is trying to use it? That would certainly cause serious problems. Do you have an idea what is happening in thread 15? Note that Hermes doesn't manage threads, event queues, etc, so this is almost certainly not a Hermes JSI problem, but perhaps we can help you narrow down the problem better. |
this is the data that occurs when the crash occurs at startup, the previous one is the data that occurs when the reload is crashed
|
As I explained at the beginning, this code is a completely new project, just adding two jsi modules, and the js part is only the template code generated by default by react-native init. The first time I observed this problem was when I found a crash when using react-native-code-push restart method. I've only recently had time to troubleshoot module by module, and have reduced it to simply initializing a new project and adding two jsi modules, cmd+r => crash |
@iwater the Hermes team does not own or maintain any of the modules you listed or the RN framework. The symptoms of the crash (crashing randomly), and the the stack traces you provided, clearly indicate that this is a threading problem caused by accessing Hermes from multiple threads, which Hermes does not control. Hermes is fundamentally single threaded, and it is the responsibility of the caller to ensure that the threading requirements are met. We can't debug these 3rd partly modules for you. I see that you have filed an issue with the author of these modules, and I hope that they can be of help. As any software, Hermes and React Native have bugs, but in order to be able to help you constructively, you need to pinpoint the problem, when it is caused by 3rd party code. |
Thanks, I understand what you mean, and based on your explanation, I know that hermes is non-thread safe and the current problem looks like it is caused by a threading issue. What I mean is that since neither module uses threads and crashes occur in the startup or loading phase, I thought the problem would be caused by a problem with the implementation of this part of the react-native loading jsi module, and react-native and hermes are closely related, so I submitted the issues here, I understand It's not your job to debug third-party modules, so I'd like to ask if there is an official standard implementation of the jsi template (forgive me, but this part is really confusing on documents, I haven't found an official recommended template implementation, and react-native is always being updated), and if there is an official recommended template implementation, I can use the latest official sample jsi template code to generate a minimal jsi module and continue testing to troubleshoot where the problem lies |
@iwater I really sympathize with your problem (that's why I reopened the issue). Unfortunately the expertise of the Hermes team doesn't extend to the area you need help with, we are all very narrowly focused on the compiler and the VM. The folks at React Native should be much better qualified to help. I know that there is a similar issue there (facebook/react-native#35720), though I am not sure what the resolution there is. I will leave this issue open a little longer with the hopes that someone from RN might chime in. |
I had a quick look at these packages, and react-native-quick-md5 is unsafely accessing the JS thread from the main thread. I'd recommend reaching out to the author of that package to correct it (especially since react-native-quick-base64 is doing this more correctly). |
Thank you @javache! Much appreciated. That's what I am talking about! Closing the issue now. |
Bug Description
When the app is launched or reloaded, it will randomly crash, I have provided screenshots and demo code, it is very easy to reproduce this problem, initialize a new react-native project, add two jsi modules, and then reload the app from the dev menu, it will randomly crash, the crash probability is very high, actually if there is only one jsi module, it will also crash, but the reproduction probability is low, I found that if there are two jsi modules, the crash is very easy to reproduce
gradle clean
and confirmed this bug does not occur with JSCHermes version: 0.71.8
React Native version (if any): 0.71.8
OS version (if any): iOS 16.2
Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): arm64-v8
Steps To Reproduce
code example:
demo code https://github.com/iwater/bug_demo
The text was updated successfully, but these errors were encountered: