GeezerVison is showing github.com — Fix native module loading in multi-context (--experimental-workers) by rpetrich · Pull Request #21517 · nodejs/node
Conversation
rpetrich
commented
Jun 25, 2018
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Fixes native module loading from multiple contexts by saving the module metadata provided by native modules when they call node_module_register. Also fixes a race condition when multiple contexts happen to load a module at the same time.
Checklist
-
make -j4 test (UNIX), or vcbuild test (Windows) passes
- tests and/or benchmarks are included
- commit message follows commit guidelines
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Maintain metadata on loaded native modules so that if additional
contexts load the same module, the metadata will be reused and the
registration function dispatched again.
Fix race condition where if multiple contexts load modules at the same
time, it's possible one of them could fail to load.
Introduce a new addons/hello-world-from-worker test that loads and
calls a native module from the main thread, then dispatches a worker to
do the same. This ensures that a module is callable from multiple
threads/v8 isolates.
rpetrich
commented
Jun 25, 2018
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Not sure if further work should be done to cause dlopen followed by require of a native module to fail, or if addons/dlopen-ping-pong should be updated to match the new behaviour.
Also, it may be worthwhile to introduce new metadata in the node_module struct denoting whether or not a module is capable of being loaded in a alternate thread. Many native modules expect to call back into node from uv_default_loop, and this fails in a very confusing way when a native module is called from a worker.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks, @bnoordhuis. Do you have any opinions on whether the well-known symbol is the recommended approach for multi-context aware modules? Unless all modules that use well-known are expected to be multi-context aware, it suffers from the same problem as you've described in #19731.
Should I split out the race condition fix into a separate PR? Also, perhaps it makes sense to raise an error if a multi-context unaware module is loaded in an alternate context? (though that would be a breaking change—as it is now, some of these modules can be used from a single worker, provided they don't reference the uv_default_loop in an unsafe way)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Do you have any opinions on whether the well-known symbol is the recommended approach for multi-context aware modules?
I think it could be. It's new enough that we can simply say it should be multi-thread ready.
perhaps it makes sense to raise an error if a multi-context unaware module is loaded in an alternate context?
No strong opinion except that it's a breaking change. That's something to avoid unless there's a very clear benefit/cost ratio.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jun 18, 2021
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
c++
Issues and PRs that require attention from people who are familiar with C++.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|