-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Don't send JavaScript objects between isolates #4
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
Conversation
0bbd134
to
e19c500
Compare
e19c500
to
a7fcea4
Compare
@codecov-ai-reviewer review |
This comment was marked as outdated.
This comment was marked as outdated.
PR DescriptionThis pull request refactors the stack trace capture mechanism in the native module to improve performance and maintainability. It replaces the direct use of V8 objects within the stack trace capture logic with a C++ data structure, Click to see moreKey Technical ChangesThe key technical changes include:
Architecture DecisionsThe main architectural decision is to decouple the stack trace representation from the V8 API. This improves the module's resilience to V8 API changes and makes the code easier to test and maintain. The use of Dependencies and InteractionsThis change primarily affects the internal implementation of stack trace capture. It does not introduce any new external dependencies. It interacts with the V8 API for stack trace retrieval and object creation, but the interaction is now more localized. The Risk ConsiderationsThe primary risk is potential performance regressions due to the overhead of copying data between the V8 heap and the C++ data structures. However, this is mitigated by performing the V8 object creation outside the interrupt handler. Thorough testing is required to ensure that the changes do not introduce any memory leaks or race conditions. The UTF-8 conversion from V8 strings to C++ strings could potentially fail, requiring careful error handling. Notable Implementation DetailsA notable implementation detail is the use of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last time I wrote c++ I was grinding a uni assignment so hopefully these apply 🙏
|
||
// Type alias for a vector of JsStackFrame | ||
using JsStackTrace = std::vector<JsStackFrame>; | ||
|
||
// Function to be called when an isolate's execution is interrupted | ||
static void ExecutionInterrupted(Isolate *isolate, void *data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this throw in any way? If it does, it'll create a deadlock because promise->set_value(frames);
can never be called.
Only thing that looks sus is the string conversions with things like utf8_fn
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the string conversions we check for a nullptr and return a default
v8::String::Utf8Value utf8_fn(isolate, fn_name);
function_name = *utf8_fn ? *utf8_fn : "?";
f.function_name.c_str(), | ||
NewStringType::kNormal) | ||
.ToLocalChecked()) | ||
.Check(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This crashes the process for it's not defined - https://github.com/v8/v8/blob/2786ffa2b1ed3ea03e9762b281d82983867ffcb0/include/v8-maybe.h#L49. How bad is to to crash the process?
FromMaybe
looks safer: https://github.com/v8/v8/blob/2786ffa2b1ed3ea03e9762b281d82983867ffcb0/include/v8-maybe.h#L84
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen this used like this everywhere so can only assume it's ok to use 🤷♂️
https://github.com/search?q=%2FToLocalChecked%5C(%5C)%2F%20%20%2FCheck%5C(%5C)%2F&type=code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this in for now, we can get further feedback later.
Once you create v8 objects in an isolate, you cannot return them from another isolate. This PR changes it so we pass a vector of intermediate
JsStackFrame
structs and construct the v8 JavaScript objects on the correct isolate.The CI test's that were failing are now passing so this definitely fixes the intermittent issues we were seeing.