Revert "Re-inject native Node modules" #5009
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR reverts #4970. I've been thinking for some days about reverting this, and I've finally decided to go ahead.
The initial reason to fully sandbox native modules was to eliminate memory leaks. While it fixed some of the leaks (memory consumption in the own Jest repository went down by approximately 10%), this PR introduced many other issues which I've been progressively fixing:
It made the
processobject not to inherit fromEventEmitteranymore (now thateventsis re-injected, a new instance is created, but theprocessobject is an instance of the parentEventEmitter, not the re-injected one).We needed to create a
switchstatement because some of the modules cannot be re-injected (e.g. re-injectingasync_hooksmakes V8 crash); and some of them are just re-created (e.g.osmodule).We also had to nullify some references to be able to get rid of some additional memory leaks. This created other issues, like the one we tried fixing in Change the way setting up the framework works #4976.
This PR still did not solve other additional issues, like the
./childtest fromjest-workernot working on parallel execution.On top of that, when applying the newest version (
21.3.0-beta.11) to Yarn, we discovered some additional issues, which are derived from the lack of Node's initialization code (the first file executed in V8,internal/bootstrap_node, is not injected, so things likeinternal/process/next_tickare not properly initialized, making the tests fail).In theory, injecting
internal/bootstrap_nodewould fix these issues, but it might led to new ones. And since the initial problem was not to sandbox modules, but to reduce memory consumption, and we haven't really achieved that, I think the best for now is to revert. Maybe someone can pick the work done here and try pushing a bit forward.