-
Notifications
You must be signed in to change notification settings - Fork 29k
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: add buildflag to force context-aware addons #29631
Conversation
aaa73db
to
469bdbe
Compare
469bdbe
to
23733d3
Compare
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 LGTM, although a test would be great.
Since Node doesn't let you load multiple instances of a native module in the same process, even in different v8 contexts, this creates a host of problems for multi-process framework like Electron.
Just to make sure there’s no misunderstanding, this is the case for only non-context-aware addons, and that is the point of this PR, right?
23733d3
to
4d315c3
Compare
Yes indeed! Only the case for non-context-aware addons. I'll add a test as soon as i can :) |
6c5909f
to
93d2420
Compare
@addaleax i think (?) my test should cover it, it's definitely not the prettiest test i've ever written so please let me know if you think there's a better pattern for testing this kind of cli flag! |
93d2420
to
93dc647
Compare
3ac2c4a
to
c5efc2a
Compare
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.
Yeah, the test looks good to me too :)
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.
A test that checks loading a context-aware add-on works would be nice too. You can co-opt one of the other context-aware add-on tests if you like, e.g.:
diff --git a/test/addons/zlib-binding/test.js b/test/addons/zlib-binding/test.js
index b50817aa5d..7a488c9a3b 100644
--- a/test/addons/zlib-binding/test.js
+++ b/test/addons/zlib-binding/test.js
@@ -1,3 +1,4 @@
+// Flags: --force-context-aware
'use strict';
const common = require('../../common');
c5efc2a
to
094d888
Compare
094d888
to
bcef054
Compare
PR-URL: #29631 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: #29631 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
Landed in 5058c7f...f120e6d |
<a id="ERR_NON_CONTEXT_AWARE_DISABLED"></a> | ||
### ERR_NON_CONTEXT_AWARE_DISABLED | ||
|
||
A non-context-aware native addon was loaded in a process that disallows them. |
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.
including a link here for context-aware
like in the cli.md file would be helpful
@@ -393,6 +393,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | |||
"silence all process warnings", | |||
&EnvironmentOptions::no_warnings, | |||
kAllowedInEnvironment); | |||
AddOption("--force-context-aware", | |||
"disable loading non-context-aware addons", |
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.
extremely minor take it or leave it nit.. but the double negative here feels odd ... "disable ... non" ... perhaps "allow only context-aware addons" as an alternative?
PR-URL: #29631 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: #29631 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
Notable changes: * build: * Add `--force-context-aware` flag to prevent usage of native node addons that aren't context aware #29631 * deprecations: * Add documentation-only deprecation for `process._tickCallback()` #29781 * esm: * Using JSON modules is experimental again #29754 * fs: * Introduce `opendir()` and `fs.Dir` to iterate through directories #29349 * process: * Add source-map support to stack traces by using `--source-map-support` #29564 * tls: * Honor `pauseOnConnect` option #29635 * Add option for private keys for OpenSSL engines #28973 PR-URL: #29919
Notable changes: * build: * Add `--force-context-aware` flag to prevent usage of native node addons that aren't context aware #29631 * deprecations: * Add documentation-only deprecation for `process._tickCallback()` #29781 * esm: * Using JSON modules is experimental again #29754 * fs: * Introduce `opendir()` and `fs.Dir` to iterate through directories #29349 * process: * Add source-map support to stack traces by using `--source-map-support` #29564 * tls: * Honor `pauseOnConnect` option #29635 * Add option for private keys for OpenSSL engines #28973 PR-URL: #29919
Notable changes: * build: * Add `--force-context-aware` flag to prevent usage of native node addons that aren't context aware #29631 * deprecations: * Add documentation-only deprecation for `process._tickCallback()` #29781 * esm: * Using JSON modules is experimental again #29754 * fs: * Introduce `opendir()` and `fs.Dir` to iterate through directories #29349 * process: * Add source-map support to stack traces by using `--source-map-support` #29564 * tls: * Honor `pauseOnConnect` option #29635 * Add option for private keys for OpenSSL engines #28973 PR-URL: #29919
This PR adds a new cli flag
--force-context-aware
whose purpose is to prevent usage of native node addons that aren't context aware. In an embedder context, loading native addons ahas always been challenging due to the need to rebuild, to link to the rightnode.lib/dll
, and to ensure the NODE_MODULE_VERSION is correct.Since Node doesn't let you load multiple instances of a native module in the same process, even in different v8 contexts, this creates a host of problems for multi-process framework like Electron.
This new flag would allow Electron and other embedders to enforce restrictions more cleanly and prevent unexpected behavior.
More context for embedders can be found here: #18397
cc @MarshallOfSound
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes