Skip to content
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

Bug and crash fixes #1784

Merged
merged 6 commits into from
Sep 22, 2023
Merged

Bug and crash fixes #1784

merged 6 commits into from
Sep 22, 2023

Conversation

ptomato
Copy link
Contributor

@ptomato ptomato commented Sep 4, 2023

Description

This PR contains a few bug fixes for bugs which admittedly don't happen very often.

  • CMake build file syntax fix - this prevented linking any other target with libNativeScript.so (which we don't currently do, but I was trying it for an experiment)
  • A few fixes that would cause crashes if a Java exception occurred early in initialization of the Runtime or ObjectManager. These crashes prevented seeing the actual cause of the Java exception.
  • A fix for a race condition that occurred rarely with Workers.
  • A safety check for DexFactory that prevents inadvertently wiping a folder indiscriminately if passed unexpected data (say, in a test).

Recommend reviewing commit by commit.

Does your pull request have unit tests?

Testing most of the PR would depend on being able to simulate a failure early in runtime initialization - we don't currently have the infrastructure for this. Having C++ tests might help in the future.

The previous cmake code accidentally set the INTERFACE_INCLUDE_DIRECTORIES
property to the string "NATIVES_BLOB_INCLUDE_DIRECTORIES". We actually
want the value of the variable. (I don't think this affects anything in
the current build, but it complains that INTERFACE_INCLUDE_DIRECTORIES
contains a relative path if you try to link anything else against
libNativeScript.so.)
In the case where a Java exception is thrown from a JNI call, wrapped into
a C++ NativeScriptException, and caught by C++ code that re-throws it to
Java, we'd get a crash.

(Admittedly, this does not happen very much. Initializing the
ObjectManager is one of the few places where it can happen.)
Running the worker tests would occasionally hit a crash where the keywords
set contained corrupt data. I believe this is because the keywords.empty()
check was being hit in two different threads. We can supply the keywords
in an initializer list so that the set is fully populated during static
initialization.
Unlikely, but the ArgConverter calls at the beginning of Runtime::Init()
could theoretically throw a Java exception, in which case they'd be
wrapped into a C++ NativeScriptException and then re-thrown to Java. For
that to work, NativeScriptException has to be initialized.
Particularly in NativeScriptException::ReThrowToJava(), we may need to
call GetClassName before the ObjectManager is initialized. This would
cause a crash when handling exceptions early in the NativeScript runtime's
initialization process.

Luckily, GetClassName doesn't actually need to be part of ObjectManager,
it can be moved to JEnv instead.
Giving a wrong path to DexFactory can result in folders unexpectedly being
wiped. Add a safety check to DexFactory.purgeDexesByThumb() to make sure
we are only deleting files with the expected extensions.
@cla-bot cla-bot bot added the cla: yes label Sep 4, 2023
@edusperoni edusperoni merged commit df7210a into NativeScript:v8-v11 Sep 22, 2023
2 checks passed
@ptomato ptomato deleted the bugfixes branch September 22, 2023 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants