Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Run each console command in its own child process #3319

Merged
merged 16 commits into from
Sep 10, 2020

Conversation

fainashalts
Copy link
Contributor

@fainashalts fainashalts commented Aug 27, 2020

Reverts #3314

We have a fix for this now, so we can revert the reversion and put in the fix, which is in #3317.

Original PR description:

This PR runs commands from inside the truffle develop and truffle console command processes. While this PR changes the way truffle develop and truffle console work under the hood, the end user CLI experience should not be different.

These changes became necessary when we found that Node v12 does not allow UncaughtException listeners in a REPL within another NodeJS program, and that one of our dependencies uses such a listener. By running a separate REPL in a child process we are able to bypass this problem. The issue that brought this to our attention is here: #2463

In the process of this work, it became apparent that the ReplManager class we had been using to manage multiple REPLs was no longer necessary since each REPL will now be in its own process. This PR thus also removes the repl.js file and directly accesses the node REPL as needed in console.js and interpreter.js.

To test this PR, run either truffle develop or truffle console and then use these to test out any other Truffle commands that make sense: migrate --reset, compile, test, debug, etc. Everything should work as it did previously, with the exception that the --network flag will throw an error when used with truffle develop -- the only network that should be used by truffle develop is the develop network.

@gnidan gnidan changed the title Revert "Revert "Run each console command in its own child process"" Run each console command in its own child process Sep 2, 2020
@@ -40,26 +40,34 @@ module.exports = {
"@truffle/core",
"index.js"
),
consoleChild: path.join(
Copy link
Contributor

Choose a reason for hiding this comment

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

Just out of curiosity, why do we need to create a bundle for this? I guess it's because Truffle needs to use an external bundle to run the command in a separate process? It seems like this will drastically increase the size of the stuff we need to include with Truffle, huh?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason we have to create a bundle is to ensure that the console-child.js file can be properly accessed from the build version of truffle when I try to run it with the spawn. It's really just a path issue. Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm understanding that the bundle will be running this other bundle using the user's input. Yeah? This will make the distributed files a lot larger, right? I'm not trying to hold this PR up, I'm just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I follow. The file being bundled is console-child.js, which is fairly short. The cli.bundled.js file is a tiny bit bigger -- 22.842243 megabytes on develop and 22.843334 megabytes on this branch. I don't think that's particularly significant?

More to the point though, how else would you get the correct path here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but console-child.js is just the entry point. So it will probably almost double the size of the distributed stuff for Truffle. Essentially this is the same size as cli.bundled.js...which might be ok. I just wanted to point out that this seems to be a significant increase in size. Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well I checked and it is not quite double, it increases the stuff in the build folder from ~50MB to like ~72MB. Something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, yeah I think that makes sense but I don't think there's another way. The whole point is that we can run Truffle commands through the child process. So we need all of that bundled this way. If you have a suggestion for how to reduce the distributed code size I'm happy to discuss further!

Copy link
Contributor

Choose a reason for hiding this comment

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

No it's probably fine. I just wanted to bring it up as something we should be aware of :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, let's avoid having that bundle in two places :)

@eggplantzzz
Copy link
Contributor

So we decided that the best fix here would be to define an entry point at core/lib/commands/index.js. That way we don't have to bundle cli.js and consoleChild.js. Those could be just copied to the dist folder and each could require the bundle. This is just an estimation of what would need to be done. There may be a little bit off messiness surrounding dealing with cli.js and consoleChild.js as I'm not sure if there is anything (processing-wise) that needs to be done with these files.

});
}

runSpawn(inputStrings, options, callback) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should rewrite this method to not take a callback. This does not hold up this PR from being merged, I just wanted to note that here.

@@ -321,7 +310,7 @@ class DebugInterpreter {

//quit if that's what we were given
if (cmd === "q") {
return await util.promisify(this.repl.stop.bind(this.repl))();
process.exit();
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also eventually set the exit code here, no? Again, I don't think this should hold this PR up.

Copy link
Contributor

@eggplantzzz eggplantzzz left a comment

Choose a reason for hiding this comment

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

I like it!

@fainashalts fainashalts merged commit 63d2e4a into develop Sep 10, 2020
@fainashalts fainashalts deleted the revert-3314-revert-3255-spawn-repl branch September 10, 2020 20:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants