-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
src: fix async hooks crashing when there is no node context #19134
Closed
Closed
Changes from 18 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
6b76017
src: fix async hooks crashing when there is no node context
xaviergonz 84a1822
src: optimization for check for env promise hook
xaviergonz 5e9128f
src: fixed linting errors for env.cc
xaviergonz 9690b86
fix: updated with the latest code review
xaviergonz 0e4fda8
fix: made the magic number smaller and a constant
xaviergonz c938269
fix: switched back to promise creation context
xaviergonz 70169d3
fix: using a faster way to know if we are in a node context
xaviergonz 9f69beb
Merge pull request #1 from nodejs/master
xaviergonz 96a53db
Merge branch 'master' into fix-async-hooks-crash
xaviergonz cb3bba1
fix: rebase to latest master and use node_context_data constants
xaviergonz 51257ed
fix: added namespace for enum
xaviergonz 361d425
fix: storing actual pointers on the context
xaviergonz 704b418
Merge branch 'master' into fix-async-hooks-crash
xaviergonz bca7fd1
src: code review
xaviergonz 0577c29
fix: code review changes
xaviergonz 54bf6dc
fix: code review
xaviergonz 3c4d991
fix: code review changes
xaviergonz 4d20b72
fix: code review
xaviergonz d9214a7
Merge branch 'master' into fix-async-hooks-crash
xaviergonz 23fa418
src: fix async hooks crashing when there is no node context
xaviergonz c2b9b32
src: optimization for check for env promise hook
xaviergonz 4437f90
src: fixed linting errors for env.cc
xaviergonz 436919e
fix: updated with the latest code review
xaviergonz 6b095d7
fix: made the magic number smaller and a constant
xaviergonz 85cf945
fix: switched back to promise creation context
xaviergonz 76df613
fix: using a faster way to know if we are in a node context
xaviergonz 077c7a5
fix: rebase to latest master and use node_context_data constants
xaviergonz 92ec8c1
fix: added namespace for enum
xaviergonz 39b5c1f
fix: storing actual pointers on the context
xaviergonz 9c72574
src: code review
xaviergonz e91cdc0
fix: code review changes
xaviergonz 6ef891e
fix: code review
xaviergonz 5ac8e62
fix: code review changes
xaviergonz aaa53b1
fix: code review
xaviergonz 3a54578
fix: rebasing
xaviergonz 634a63e
fix: linting errors
xaviergonz 10b280e
fix: use actual magic number as ptr rather than ptr to int variable
xaviergonz e394201
fix: reinterpret cast and linting
xaviergonz af69d52
fix: better reinterpret cast
xaviergonz 927d984
fix: reverting using fixed address
xaviergonz 290b627
fix: fix for failing unit tests
xaviergonz 93d7670
Merge branch 'master' into fix-async-hooks-crash
xaviergonz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#include "node_buffer.h" | ||
#include "node_platform.h" | ||
#include "node_file.h" | ||
#include "node_context_data.h" | ||
#include "tracing/agent.h" | ||
|
||
#include <stdio.h> | ||
|
@@ -24,6 +25,10 @@ using v8::StackTrace; | |
using v8::String; | ||
using v8::Value; | ||
|
||
const int kNodeContextTag = 0x6e6f64; | ||
void* kNodeContextTagPtr = const_cast<void*>( | ||
static_cast<const void*>(&kNodeContextTag)); | ||
|
||
IsolateData::IsolateData(Isolate* isolate, | ||
uv_loop_t* event_loop, | ||
MultiIsolatePlatform* platform, | ||
|
@@ -195,6 +200,10 @@ void Environment::Start(int argc, | |
set_process_object(process_object); | ||
|
||
SetupProcessObject(this, argc, argv, exec_argc, exec_argv); | ||
|
||
// Used by EnvPromiseHook to know that we are on a node context. | ||
context()->SetAlignedPointerInEmbedderData(ContextEmbedderIndex::kContextTag, kNodeContextTagPtr); | ||
|
||
LoadAsyncWrapperInfo(this); | ||
|
||
static uv_once_t init_once = UV_ONCE_INIT; | ||
|
@@ -364,7 +373,19 @@ bool Environment::RemovePromiseHook(promise_hook_func fn, void* arg) { | |
void Environment::EnvPromiseHook(v8::PromiseHookType type, | ||
v8::Local<v8::Promise> promise, | ||
v8::Local<v8::Value> parent) { | ||
Environment* env = Environment::GetCurrent(promise->CreationContext()); | ||
Local<v8::Context> context = promise->CreationContext(); | ||
|
||
// Grow the embedder data if necessary to make sure we are not out of bounds | ||
// when reading the magic number. | ||
context->SetAlignedPointerInEmbedderData(ContextEmbedderIndex::kContextTagBoundary, nullptr); | ||
int* magicNumberPtr = reinterpret_cast<int*>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: If you |
||
context->GetAlignedPointerFromEmbedderData(ContextEmbedderIndex::kContextTag)); | ||
if (magicNumberPtr != kNodeContextTagPtr) { | ||
return; | ||
} | ||
|
||
Environment* env = Environment::GetCurrent(context); | ||
|
||
for (const PromiseHookCallback& hook : env->promise_hooks_) { | ||
hook.cb_(type, promise, parent, hook.arg_); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 should probably be happening in
Environment::AssignToContext
rather than here… that means thatkNodeContextTag
would have to be in a more public location (e.g. as a static private variable ofEnvironment
), but I think that’s fine?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.
that one might take a while. I'd need to clone the whole repo again, etc etc.