NativeScript / android

NativeScript for Android using v8
https://docs.nativescript.org/guide/android-marshalling
Apache License 2.0
530 stars 135 forks source link

fix: `exit(0)` causes ANR due to destroyed mutex #1820

Closed mukaschultze closed 1 month ago

mukaschultze commented 3 months ago

Description

When initializing the runtime in direct boot mode the exit(0) IO cleanup causes a SIGABRT with the following message:

libc    : FORTIFY: pthread_mutex_destroy called on a destroyed mutex (0x759399de1718)

This SIGABRT is caught by the SIG_handler which in turn throws a tsn::NativeScriptException. I'm not exactly sure what catches this NativeScriptException, but whatever it is either deadlocks or keeps re-throwing it until the device runs out of memory.

https://github.com/NativeScript/android/blob/ba50f0337c407a51121fe6fd310c6289eb3e3796/test-app/runtime/src/main/cpp/Runtime.cpp#L49-L66

This bug shows up as an ANR (App not responding) in Crashlytics and Google Play console (as reported in https://github.com/NativeScript/NativeScript/issues/10527).

The same issue was reported on https://github.com/flutter/flutter/issues/103587, which leads me to believe this is not specific to Nativescript's runtime.

My proposed solution is to use _Exit(0) instead, which doesn't trigger any cleanup process and simply ends the process.

Full error below:

08-28 13:56:32.187  1506  1506 D TNS.Runtime: V8 version 10.3.22
08-28 13:56:32.191  1506  1506 E TNS.error: metadata folder couldn't be opened! (Error: 2) 
--------- beginning of crash
08-28 13:56:32.191  1506  1506 F libc    : FORTIFY: pthread_mutex_destroy called on a destroyed mutex (0x759399de1718)
08-28 13:56:32.191  1506  1506 F TNS.Native: JNI Exception occurred (SIGABRT).
08-28 13:56:32.191  1506  1506 F TNS.Native: =======
08-28 13:56:32.191  1506  1506 F TNS.Native: Check the 'adb logcat' for additional information about the error.
08-28 13:56:32.191  1506  1506 F TNS.Native: =======
08-28 13:56:32.191  1506  1506 E libc++abi: terminating with uncaught exception of type tns::NativeScriptException

Related Pull Requests

https://github.com/NativeScript/android/pull/1712 https://github.com/NativeScript/plugins/issues/262 https://github.com/NativeScript/NativeScript/issues/10527

Does your pull request have unit tests?