Skip to content
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

fix: enable use of NODE_OPTIONS env var #15158

Merged
merged 1 commit into from
Oct 18, 2018
Merged

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Oct 14, 2018

Description of Change

Enables use of NODE_OPTIONS environment variable in Electron.

Depends on electron/node#76.

Potential concerns: options relating to V8 that may cause collisions should they misalign with Blink's V8 usage.

/cc @deepak1556

Checklist

  • PR description included and stakeholders cc'd
  • npm test passes
  • PR title follows semantic commit guidelines

Release Notes

Notes: Enable use of NODE_OPTIONS env var

@codebytere codebytere changed the title [WIP] fix: enable use of NODE_OPTIONS fix: enable use of NODE_OPTIONS Oct 14, 2018
Copy link
Contributor

@alexeykuzmin alexeykuzmin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codebytere
We should remove NODE_WITHOUT_NODE_OPTIONS define from the e/node's BUILD.gn:
https://github.com/electron/node/blob/f14ddf9d7e07739dc1dc0cbe2f7a5ba8b44906d1/BUILD.gn#L155

@alexeykuzmin
Copy link
Contributor

Can we add a test that NODE_OPTIONS work?

@codebytere
Copy link
Member Author

codebytere commented Oct 15, 2018

@alexeykuzmin they do locally, will try to add a spec; also, your requested changes are a PR that was already linked in the PR body.

@nornagon
Copy link
Member

What was the initial reason to remove support for NODE_OPTIONS?

@codebytere
Copy link
Member Author

codebytere commented Oct 15, 2018

@nornagon it was never removed, it was always broken from the very beginning since we passed nullptr to node::Init which meant that when Init tried to index into argv it would segfault. A little while back we fixed the segfault by defining NODE_WITHOUT_NODE_OPTIONS, so this PR is the first attempt at actually making them work 😁

@nornagon
Copy link
Member

ahh, gotcha!

@MarshallOfSound MarshallOfSound mentioned this pull request Oct 15, 2018
2 tasks
@deepak1556
Copy link
Member

The changes LGTM, also needs to update for standalone node mode in atom/app/node_main.cc.

Just need some clarification, what is the benefit of enabling this for electron ? This actually removes the control of node argument parsing away from us, now some of the node options are parsed and enabled from an environment variable, which seems to bypass the blacklist we maintain when the executable is invoked through a protocol handler.

atom/common/node_bindings.cc Outdated Show resolved Hide resolved
atom/common/node_bindings.cc Outdated Show resolved Hide resolved
@alexeykuzmin alexeykuzmin dismissed their stale review October 17, 2018 20:12

Because I want to

@codebytere codebytere requested a review from a team October 17, 2018 20:27
@codebytere codebytere changed the title fix: enable use of NODE_OPTIONS fix: enable use of NODE_OPTIONS env var Oct 17, 2018
@codebytere
Copy link
Member Author

codebytere commented Oct 17, 2018

@nornagon @alexeykuzmin @deepak1556 @nitsakh in addition to the advisory warnings above, what are your thoughts on my also explicitly disallowing all NODE_OPTIONS in packaged apps?

int exec_argc = 0;
const char** argv = nullptr;
const char* prog_name = "electron";
const char** argv = {&prog_name};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the brackets for here?

atom/common/node_bindings.cc Outdated Show resolved Hide resolved
atom/common/node_bindings.cc Outdated Show resolved Hide resolved

// parse passed options for unsupported options
// and remove them from the options list
for (std::string part : parts) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to create a new temporary; can use std::string& part

atom/common/node_bindings.cc Outdated Show resolved Hide resolved
std::size_t found = disallow.find(part);
if (found != std::string::npos) {
LOG(WARNING) << "This NODE_OPTION is not supported in Electron";
parts.erase(std::remove(parts.begin(), parts.end(), part),
Copy link
Member

@ckerr ckerr Oct 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You _really _ don't want to be modifying the parts vector while iterating through it in the outermost loop here.

I'd suggest you do something more like

std::vector<std::string> tmp;
for (const auto& part : parts) {
  if (disallow.count(part)) {
    warning...
  } else {
    tmp.push_back(part);
  }
}
std::swap(parts, tmp);

if (!is_first_round)
new_options << " ";
new_options << part;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might try something like this:

std::copy(
  parts.begin(), parts.end(),
  std::ostream_iterator<std::string>(new_options," "));

@deepak1556
Copy link
Member

If we are disabling them completely for packaged apps and allowing otherwise, the current options parsing and warning in this PR won't be required, only a simplified warning in packaged mode would be needed to state NODE_OPTIONS don't work in this mode.

@codebytere codebytere force-pushed the enable-node-options branch 2 times, most recently from 9e9f89a to 7af2eff Compare October 17, 2018 23:37
Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of suggestions inline, but nothing major. LGTM!

std::transform(path.begin(), path.end(), path.begin(), ::tolower);

#if defined(OS_WIN)
is_packaged_app = path == "electron.exe";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) the advance declaration above could be removed and these two lines could be

#if defined(OS_WIN)
  const bool is_packaged_app = path == "electron.exe";
#else
  const bool is_packaged_app = path == "electron";
#endif

if (is_packaged_app) {
env->SetVar("NODE_OPTIONS", "");
} else {
std::vector<std::string> disallowed = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) this can be const std::vector<std::string>

Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this final-draft revision on a C++ level. This code LGTM and I'd be fine with it landing.

I don't have any opinion on how to NODE_OPTIONS wrt packaging. If someone feels strongly about that, please weigh in before this merges. 😐

@release-clerk
Copy link

release-clerk bot commented Oct 18, 2018

Release Notes Persisted

Enable use of NODE_OPTIONS env var

@trop
Copy link
Contributor

trop bot commented Oct 18, 2018

We have automatically backported this PR to "4-0-x", please check out #15259

@trop trop bot added merged/4-0-x and removed target/4-0-x labels Oct 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants