GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix native module loading in multi-context (--experimental-workers) by rpetrich · Pull Request #21517 · nodejs/node

Conversation

@rpetrich

@rpetrich rpetrich commented Jun 25, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
@rpetrich
src: permit native modules to be loaded in more than one context
78159c3
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.
@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Jun 25, 2018
@rpetrich
test: add test for loading native modules from multiple contexts
ffdc0c0
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
rpetrich force-pushed the multi-context-modules branch from 77e181e to ffdc0c0 Compare June 25, 2018 04:06
@rpetrich rpetrich mentioned this pull request Jun 25, 2018
Add support for running inside a node 10.5 worker_thread TryGhost/node-sqlite3#1007
Merged
@rpetrich

rpetrich commented Jun 25, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Jun 25, 2018

Copy link
Copy Markdown
Member

See #19731 (review). This PR has the same issue.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rpetrich

rpetrich commented Jun 28, 2018

Copy link
Copy Markdown
Contributor Author

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)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Jun 28, 2018

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rpetrich rpetrich closed this Jul 15, 2018
This was referenced Jun 18, 2021
[Snyk] Security upgrade gatsby from 2.18.18 to 2.19.25 ron-a20/node#34
Open
[Snyk] Security upgrade gatsby from 2.18.18 to 2.19.25 aliceUnhinged613/node#26
Open
[Snyk] Security upgrade gatsby from 2.13.73 to 2.19.25 meghasfdc/node#36
Open
[Snyk] Security upgrade gatsby from 2.13.73 to 2.19.25 kissofire/node#36
Open
[Snyk] Security upgrade gatsby from 2.18.18 to 2.19.25 137717unity/node#27
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

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++.

Projects

None yet

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.

3 participants

@rpetrich @bnoordhuis @nodejs-github-bot
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.