Skip to content

Conversation

@guybedford
Copy link
Contributor

@guybedfordguybedford commented Oct 11, 2019

This PR includes refactoring parts of the --experimental-modules unflagging in #29866, without actually unflagging --experimental-modules yet, in turn simplifying the unflagging PR.

The main aspect of this is separating out the runMain bootstrap from CJS, and very carefully ensuring that the async bootstrap and modules promise creation only applies when absolutely necessary, to avoid any async hooks noise.

The various other changes are there to fix test cases that fail under unflagging, I will provide context with code comments below.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-botnodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Oct 11, 2019
@guybedfordguybedfordforce-pushed the async-bootstrap-refactor branch from 880166a to aa4e8b5CompareOctober 11, 2019 21:48
@guybedfordguybedford mentioned this pull request Oct 11, 2019
14 tasks
@Fishrock123Fishrock123 added esm Issues and PRs related to the ECMAScript Modules implementation. module Issues and PRs related to the module subsystem. labels Oct 12, 2019
@guybedfordguybedfordforce-pushed the async-bootstrap-refactor branch from e662b3e to c4b3832CompareOctober 13, 2019 03:05
@Trott
Copy link
Member

@nodejs/modules-active-members This could use some reviews.

Copy link
Contributor

@MylesBorinsMylesBorins left a comment

Choose a reason for hiding this comment

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

RSLGTM assuming tests are all passing.

@nodejs-github-bot
Copy link
Collaborator

@guybedfordguybedfordforce-pushed the async-bootstrap-refactor branch from c4b3832 to 521f518CompareOctober 14, 2019 21:25
@guybedfordguybedfordforce-pushed the async-bootstrap-refactor branch from dfd3398 to ab9f8cdCompareOctober 14, 2019 21:36
@guybedfordguybedfordforce-pushed the async-bootstrap-refactor branch from ab9f8cd to c750488CompareOctober 14, 2019 21:47
@guybedfordguybedford requested a review from TrottOctober 16, 2019 18:15
@TrottTrott dismissed their stale reviewOctober 16, 2019 18:28

test was fixed hooray!

@TrottTrott added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Oct 16, 2019
guybedford pushed a commit that referenced this pull request Oct 17, 2019
PR-URL: #29937 Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
@guybedford
Copy link
ContributorAuthor

Landed in a6b030d.

@guybedfordguybedford deleted the async-bootstrap-refactor branch October 17, 2019 01:51
MylesBorins pushed a commit that referenced this pull request Oct 23, 2019
PR-URL: #29937 Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
MylesBorins pushed a commit that referenced this pull request Oct 23, 2019
PR-URL: #29937 Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
@MylesBorinsMylesBorins mentioned this pull request Oct 23, 2019
aduh95 pushed a commit to aduh95/node that referenced this pull request Jan 7, 2020
PR-URL: nodejs#29937 Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
@targos
Copy link
Member

this lands cleanly on v12.x-staging, but it breaks a test:

Command: out/Release/node /home/mzasso/git/nodejs/v12.x/test/parallel/test-repl-tab-complete-nested-repls.js --- TIMEOUT --- [02:19|% 100|+ 2797|- 1]: Done 

@MylesBorins
Copy link
Contributor

/cc @bmeck@guybedford could you please take a look... i did some digging and can't figure out what is broken here... seems related to domains 😅

@guybedford
Copy link
ContributorAuthor

I had a quick look at this this morning, and it seems like this is some interaction with domain where the error being thrown in run_main_module.js isn't being picked up somehow. If you wrap runMain in a try-catch the error is there fine and synchronously. If you check ExecuteBootstrapper in node.cc the result of the run_main_module call satisfies result.isEmpty() (signalling an error). So somehow the exception handler is just not attaching from there.

I'm not sure what code paths this would be corresponding to personally. @joyeecheung@addaleax perhaps you have some ideas on this?

@guybedford
Copy link
ContributorAuthor

@targos@MylesBorins I finally tracked down where in the PR this code change was coming from. The following patch should fix the issue:

diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 7dd0475d48..75300ae942 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -1134,6 +1134,7 @@ Module._extensions['.node'] = function(module, filename){Module.runMain = function(main = process.argv[1]){const resolvedMain = resolveMainPath(main); const useESMLoader = shouldUseESMLoader(resolvedMain); + module.exports.asyncRunMain = useESMLoader; if (useESMLoader){runMainESM(resolvedMain || main)} else{diff --git a/lib/repl.js b/lib/repl.js index 6e22bd43a9..2871bab27d 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -65,7 +65,8 @@ const path = require('path'); const fs = require('fs'); const{Interface } = require('readline'); const{Console } = require('console'); -const CJSModule = require('internal/modules/cjs/loader').Module; +const cjsLoader = require('internal/modules/cjs/loader'); +const{Module: CJSModule } = cjsLoader; const domain = require('domain'); const debug = require('internal/util/debuglog').debuglog('repl'); const{@@ -1081,6 +1082,8 @@ function complete(line, callback){// bufferedCommand. if (!magic[kBufferedCommandSymbol]){magic._domain.on('error', (err) =>{+ if (!cjsLoader.asyncRunMain) + throw err; setImmediate(() =>{throw err}); 

MylesBorins pushed a commit that referenced this pull request Jan 12, 2020
PR-URL: #29937 Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
@MylesBorins
Copy link
Contributor

@guybedford it looks like the repl test isn't failing on 13.x because #30907 refactored the code that was throwing. Thanks @BridgeAR

I don't think we need a backport-pr anymore tbh and have pushed to staging.

@targostargos mentioned this pull request Jan 15, 2020
BethGriggs pushed a commit that referenced this pull request Feb 6, 2020
PR-URL: #29937 Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
@MylesBorinsMylesBorins mentioned this pull request Feb 8, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.esmIssues and PRs related to the ECMAScript Modules implementation.lib / srcIssues and PRs related to general changes in the lib or src directory.moduleIssues and PRs related to the module subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@guybedford@Trott@nodejs-github-bot@MylesBorins@targos@joyeecheung@richardlau@Fishrock123@bfarias-godaddy