Skip to content

Conversation

@codebytere
Copy link
Member

@codebyterecodebytere 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-botnodejs-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
MemberAuthor

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")){
returnStartExecution(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"){
returnStartExecution(env, "internal/main/inspect");
}
if (per_process::cli_options->print_help){
returnStartExecution(env, "internal/main/print_help");
}
if (env->options()->prof_process){
returnStartExecution(env, "internal/main/prof_process");
}
// -e/--eval without -i/--interactive
if (env->options()->has_eval_string && !env->options()->force_repl){
returnStartExecution(env, "internal/main/eval_string");
}
if (env->options()->syntax_check_only){
returnStartExecution(env, "internal/main/check_syntax");
}
if (!first_argv.empty() && first_argv != "-"){
returnStartExecution(env, "internal/main/run_main_module");
}
if (env->options()->force_repl || uv_guess_handle(STDIN_FILENO) == UV_TTY){
returnStartExecution(env, "internal/main/repl");
}
returnStartExecution(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

@addaleaxaddaleax 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

@codebyterecodebytere changed the title src,lib: don't run bootstrapper in CreateEnvironmentsrc: don't run bootstrapper in CreateEnvironmentFeb 26, 2020
@codebyterecodebytereforce-pushed the createenv-remove-some=bootstrap branch from 20a67b2 to 26a8571CompareFebruary 26, 2020 16:44
@nodejs-github-bot
Copy link
Collaborator

@codebyterecodebytereforce-pushed the createenv-remove-some=bootstrap branch from 26a8571 to 57fe1c6CompareFebruary 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 <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
@codebytere
Copy link
MemberAuthor

Landed in 65e18a8

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

🎉 Thanks for landing this!

@addaleaxaddaleax 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 <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
@codebyterecodebytere 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 <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
codebytere added a commit that referenced this pull request Mar 17, 2020
PR-URL: #31910 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
@codebyterecodebytere 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 <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
codebytere added a commit that referenced this pull request Mar 30, 2020
PR-URL: #31910 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
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 <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
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 <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

buildIssues 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

@codebytere@gireeshpunathil@himself65@joyeecheung@nodejs-github-bot@addaleax