Skip to content

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Feb 22, 2020

Refs electron/electron#22342.

#26788 added a call to prepareMainThreadExecution to CreateEnvironment, which would prepare the main thread for execution any time an embedder created a new environment. However, this caused an unfortunate doubling-up effect, and meant that Electron would see stuff like:

> process.emit('warning', new Error('warn'))
(node:55797) Error: warn
(node:55797) Error: warn

Since both execution pathways (env and whatever the actual execution was) were being exercised. To fix this, I believe we should remove bootstrapping code from CreateEnvironment.

cc @joyeecheung @addaleax

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to build files or the CI. c++ Issues and PRs that require attention from people who are familiar with C++. labels Feb 22, 2020
@gireeshpunathil
Copy link
Member

where is the other bootstrapping that is happening?

@codebytere
Copy link
Member Author

codebytere commented Feb 22, 2020

@gireeshpunathil:

node/src/node.cc

Lines 404 to 448 in 84b8857

MaybeLocal<Value> StartMainThreadExecution(Environment* env) {
// To allow people to extend Node in different ways, this hook allows
// one to drop a file lib/_third_party_main.js into the build
// directory which will be executed instead of Node's normal loading.
if (NativeModuleEnv::Exists("_third_party_main")) {
return StartExecution(env, "internal/main/run_third_party_main");
}
std::string first_argv;
if (env->argv().size() > 1) {
first_argv = env->argv()[1];
}
if (first_argv == "inspect" || first_argv == "debug") {
return StartExecution(env, "internal/main/inspect");
}
if (per_process::cli_options->print_help) {
return StartExecution(env, "internal/main/print_help");
}
if (env->options()->prof_process) {
return StartExecution(env, "internal/main/prof_process");
}
// -e/--eval without -i/--interactive
if (env->options()->has_eval_string && !env->options()->force_repl) {
return StartExecution(env, "internal/main/eval_string");
}
if (env->options()->syntax_check_only) {
return StartExecution(env, "internal/main/check_syntax");
}
if (!first_argv.empty() && first_argv != "-") {
return StartExecution(env, "internal/main/run_main_module");
}
if (env->options()->force_repl || uv_guess_handle(STDIN_FILENO) == UV_TTY) {
return StartExecution(env, "internal/main/repl");
}
return StartExecution(env, "internal/main/eval_stdin");
}

See that all those js files call prepareMainThreadExecution(true).

@himself65
Copy link
Member

related: #31909

@joyeecheung
Copy link
Member

By the way, I think a quick band-aid fix to this issue without introducing breaking changes would be to maintain something like isInitialized in pre_execution.js for prepareMainThreadExecution() and return early there if it's set to true. It's not ideal but would lead to less impact.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

LGTM

#30467 contains a non-breaking version of this along the lines of what Joyee suggested, but given that I don’t see how the current state is usable, I’m good with landing this as a semver-patch change.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@codebytere codebytere changed the title src,lib: don't run bootstrapper in CreateEnvironment src: don't run bootstrapper in CreateEnvironment Feb 26, 2020
@codebytere codebytere force-pushed the createenv-remove-some=bootstrap branch from 20a67b2 to 26a8571 Compare February 26, 2020 16:44
@nodejs-github-bot
Copy link
Collaborator

@codebytere codebytere force-pushed the createenv-remove-some=bootstrap branch from 26a8571 to 57fe1c6 Compare February 27, 2020 05:58
@nodejs-github-bot
Copy link
Collaborator

codebytere added a commit that referenced this pull request Feb 27, 2020
PR-URL: #31910
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@codebytere
Copy link
Member Author

Landed in 65e18a8

@codebytere codebytere closed this Feb 27, 2020
@codebytere codebytere deleted the createenv-remove-some=bootstrap branch February 27, 2020 21:50
@addaleax
Copy link
Member

🎉 Thanks for landing this!

@addaleax addaleax mentioned this pull request Feb 28, 2020
4 tasks
codebytere added a commit that referenced this pull request Feb 29, 2020
PR-URL: #31910
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@codebytere codebytere mentioned this pull request Feb 29, 2020
addaleax added a commit to addaleax/node that referenced this pull request Mar 12, 2020
codebytere added a commit that referenced this pull request Mar 15, 2020
PR-URL: #31910
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
codebytere added a commit that referenced this pull request Mar 17, 2020
PR-URL: #31910
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@codebytere codebytere mentioned this pull request Mar 17, 2020
addaleax added a commit that referenced this pull request Mar 21, 2020
Refs: #31910

PR-URL: #30467
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
codebytere added a commit that referenced this pull request Mar 30, 2020
PR-URL: #31910
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
codebytere added a commit to electron/electron that referenced this pull request Apr 13, 2020
addaleax added a commit to addaleax/node that referenced this pull request Sep 23, 2020
Refs: nodejs#31910

PR-URL: nodejs#30467
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
addaleax added a commit that referenced this pull request Sep 23, 2020
Refs: #31910

Backport-PR-URL: #35241
PR-URL: #30467
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. c++ Issues and PRs that require attention from people who are familiar with C++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants