-
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 race on modpending by migrating it to a thread local #21611
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -185,7 +185,8 @@ static int v8_thread_pool_size = v8_default_thread_pool_size; | |
static bool prof_process = false; | ||
static bool v8_is_profiling = false; | ||
static bool node_is_initialized = false; | ||
static node_module* modpending; | ||
static uv_once_t init_once = UV_ONCE_INIT; | ||
static uv_key_t thread_local_modpending; | ||
static node_module* modlist_builtin; | ||
static node_module* modlist_internal; | ||
static node_module* modlist_linked; | ||
|
@@ -1144,7 +1145,7 @@ extern "C" void node_module_register(void* m) { | |
mp->nm_link = modlist_linked; | ||
modlist_linked = mp; | ||
} else { | ||
modpending = mp; | ||
uv_key_set(&thread_local_modpending, mp); | ||
} | ||
} | ||
|
||
|
@@ -1258,6 +1259,10 @@ inline napi_addon_register_func GetNapiInitializerCallback(DLib* dlib) { | |
reinterpret_cast<napi_addon_register_func>(dlib->GetSymbolAddress(name)); | ||
} | ||
|
||
void InitDLOpenOnce() { | ||
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. This should be |
||
CHECK_EQ(0, uv_key_create(&thread_local_modpending)); | ||
} | ||
|
||
// DLOpen is process.dlopen(module, filename, flags). | ||
// Used to load 'module.node' dynamically shared objects. | ||
// | ||
|
@@ -1268,7 +1273,8 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) { | |
Environment* env = Environment::GetCurrent(args); | ||
auto context = env->context(); | ||
|
||
CHECK_NULL(modpending); | ||
uv_once(&init_once, InitDLOpenOnce); | ||
CHECK_NULL(uv_key_get(&thread_local_modpending)); | ||
|
||
if (args.Length() < 2) { | ||
env->ThrowError("process.dlopen needs at least 2 arguments."); | ||
|
@@ -1296,8 +1302,9 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) { | |
// Objects containing v14 or later modules will have registered themselves | ||
// on the pending list. Activate all of them now. At present, only one | ||
// module per object is supported. | ||
node_module* const mp = modpending; | ||
modpending = nullptr; | ||
node_module* const mp = static_cast<node_module*>( | ||
uv_key_get(&thread_local_modpending)); | ||
uv_key_set(&thread_local_modpending, nullptr); | ||
|
||
if (!is_opened) { | ||
Local<String> errmsg = OneByteString(env->isolate(), dlib.errmsg_.c_str()); | ||
|
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.
The name of this variable should indicate that it refers to
thread_local_modpending
– so, like, maybeinit_modpending_once
?