GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — src: fix race on modpending by migrating it to a thread local by rpetrich · Pull Request #21611 · nodejs/node Conversation
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Almost any use of Environment::GetThreadLocalEnv() is going to be buggy, because Node.js generally seeks to support embedders who create multiple Environments per thread :(
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@addaleax Thanks, I was unaware of that. I've migrated to using a thread local instead, which should properly support multiple Environments per thread.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
18b1cde to
5c3e676
Compare
Fixes a rare race condition on modpending when two native modules are loaded simultaneously on different threads by migrating modpending to be a member of Environment.
5c3e676 to
7f2c8bf
Compare
|
@addaleax modules which rely on Assuming the node environment on such a thread is correctly set up to be indistinguishable from a single-threaded node environment such addons will work correctly because the one thread where they do load is the only thread where they need to work and they will not subsequently load because the library constructors will not fire again. In contrast, when using a special symbol a module must support multiple init and module-instance-local storage, because such a symbol will be found every time the module is loaded, no matter what thread it's on and no matter that it's multiple times on a single thread. So, I think landing this PR will help us, and will not cause any more breakage than the current inability to load a module more than once already causes. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 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; |
There was a problem 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, maybe init_modpending_once?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| reinterpret_cast<napi_addon_register_func>(dlib->GetSymbolAddress(name)); | ||
| } | ||
|
|
||
| void InitDLOpenOnce() { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This should be InitModpendingOnce, not InitDLOpenOnce.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I was able to cause by running the following code: /* index.js */ const assert = require('assert'); const { Worker, isMainThread, parentPort } = require('worker_threads'); if (isMainThread) { let robinHood; (new Worker(__filename)).on('message', (data) => { if (data === 'ready') { robinHood = JSON.stringify(require('./build/Release/robin_hood')); } else { console.log(data + '\nvs.\n' + robinHood); assert.notStrictEqual(data, robinHood); } }); } else { parentPort.postMessage('ready'); parentPort.postMessage(JSON.stringify(require('./build/Release/friar_tuck'))); } where /* robin_hood.c */ #include <assert.h> #include <node_api.h> static napi_value Init(napi_env env, napi_value exports) { napi_status status; napi_value result; status = napi_create_uint32(env, 42, &result); assert(status == napi_ok); status = napi_set_named_property(env, exports, "answer", result); assert(status == napi_ok); return exports; } NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) and /* friar_tuck.c */ #include <assert.h> #include <node_api.h> static napi_value Init(napi_env env, napi_value exports) { napi_status status; napi_value result; status = napi_create_string_utf8(env, "good", NAPI_AUTO_LENGTH, &result); assert(status == napi_ok); status = napi_set_named_property(env, exports, "question", result); assert(status == napi_ok); return exports; } NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) in a shell loop with while node --experimental-worker ./index.js; do echo -n ''; done It's not deterministic though so it doesn't serve as a good test. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@addaleax I believe that using In conclusion, using |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@gabrielf that all makes sense to me. I guess we just need to get this PR updated based on your comments and the it looks good to me. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@rpetrich do you think you might be able to find the time to address my comments so we can move the PR forward? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@gabrielschulhof Thanks for pushing to the PR. I'd missed the earlier comments about naming. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@rpetrich happy to help! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@mhdawson could you PTAL? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@nodejs/addon-api could someone else please also take a look? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@nodejs/collaborators could someone please have a look? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
CI resumed as https://ci.nodejs.org/job/node-test-pull-request/16483/ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
New CI: https://ci.nodejs.org/job/node-test-pull-request/16484/ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
FreeBSD rebuild: https://ci.nodejs.org/job/node-test-commit-freebsd/19726/ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think FreeBSD is back to green. Let's try a Resume Build: https://ci.nodejs.org/job/node-test-pull-request/16501/ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Landed in 3814534. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Fixes a rare race condition on modpending when two native modules are loaded simultaneously on different threads by storing it thread- locally. PR-URL: #21611 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
Fixes a rare race condition on modpending when two native modules are loaded simultaneously on different threads by storing it thread- locally. PR-URL: #21611 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
Fixes a rare race condition on modpending when two native modules are loaded simultaneously on different threads by storing it thread- locally. PR-URL: #21611 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.