-
Notifications
You must be signed in to change notification settings - Fork 47
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
JVM doesn't terminate when using Hybrids #25
Comments
It's been more than 2 years and this is still an issue. From what I can tell this is a textbook daemon thread? Can we please do at least one of the following:
I'm happy to provide a pull request (these are all O(1) line changes) if there's interest, thanks! |
It appears that Android doesn't really care if a thread is marked as a daemon or not: https://stackoverflow.com/a/15323954/708381
This makes me vote strongly in favor of option 1, just mark the thread as a daemon for all users. |
Yeah, I want to do this. I just haven't had time. It's very hard to verify that this doesn't cause some subtle but insidious problem on any version of Android. |
User threads block the VM from exiting. Daemon threads do not. That is their superficial difference. According to https://stackoverflow.com/a/2213443/708381 (and this matches what I've read elsewhere), daemon threads are abandoned and e.g. finally blocks are not executed when the JVM exits. This means that any That of course sounds scary - it's presumably important to call But if the other SO post is to be believed, then this is already the case on Android: "Your app's process never exits: It either remains in the background or it gets killed at some point". That means it was always possible for a |
If you're still concerned about Android (and I don't blame you if you are), then how about: if (!"The Android Project".equals(System.getProperty("java.vendor"))) sThread.setDaemon(true); Based on https://stackoverflow.com/questions/4519556/how-to-determine-if-my-app-is-running-on-android and https://developer.android.com/reference/java/lang/System#getProperties() |
@dreiss can we please get this resolved? I'm happy to contribute whichever of the lines below you'll accept: if (!"The Android Project".equals(System.getProperty("java.vendor"))) sThread.setDaemon(true);
if ("true".equals(System.getProperty("com.facebook.fbjni.setDaemon"))) sThread.setDaemon(true);
if ("true".equals(System.getProperty("fbjni.setDaemon"))) sThread.setDaemon(true);
sThread.setDaemon(true); // <-- already ready & waiting in pull request #67 If in doubt I recommend: if ("true".equals(System.getProperty("fbjni.setDaemon"))) sThread.setDaemon(true); That makes it 100% opt-in, and calling code can easily put a This is blocking normal dev operation, and it blocks normal Java process exit in production as well. |
It would help me to resolve this issue, whichever way - calling |
Issue description
In any program that uses HybridData, the JVM will not terminate when
main
returns. CallingSystem.exit
still terminates cleanly. This appears to be because the Hybrid Destructor thread is not marked as a daemon thread. CallingsThread.setDaemon(true);
resolves the issue, but I'm not sure if it can cause issues on Android.Code example
Apply this patch:
Running as
./gradlew -b host.gradle run --args nope
causes the app to run forever.Running as
./gradlew -b host.gradle run --args exit
causes the app to terminate quickly.System Info
Linux.
The text was updated successfully, but these errors were encountered: