Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babel-node doesn't respect --max_old_space_size option when working with cluster #12635

Closed
ryancat opened this issue Jan 14, 2021 · 5 comments · Fixed by #12638
Closed

Babel-node doesn't respect --max_old_space_size option when working with cluster #12635

ryancat opened this issue Jan 14, 2021 · 5 comments · Fixed by #12638
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: node

Comments

@ryancat
Copy link

ryancat commented Jan 14, 2021

Bug Report

Current behavior

This are some codes on REPL that shows the error. Basically, babel-node doesn't respect the --max_old_space_size option when running with cluster. The out of memory exception will throw regardless of the extra memory allocated. Running without cluster everything works.

Expected behavior

Babel-node should work with cluster as well when --max_old_space_size is provided.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
Just install @babel/node and @babel/core.

Environment

$ npx envinfo --preset babel
npx: installed 1 in 1.377s

  System:
    OS: macOS 10.15.7
  Binaries:
    Node: 10.16.3 - ~/.nvm/versions/node/v10.16.3/bin/node
    Yarn: 1.22.4 - ~/.nvm/versions/node/v10.16.3/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v10.16.3/bin/npm
  npmPackages:
    @babel/core: ~7.8 => 7.8.7 
    @babel/node: ~7.8 => 7.8.7 
    @babel/runtime: ~7.8 => 7.8.7 

Possible Solution

The only solution right now is to add NODE_OPTIONS=--max-old-space-size=4096 before node.

@babel-bot
Copy link
Collaborator

Hey @ryancat! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@JLHwung
Copy link
Contributor

JLHwung commented Jan 14, 2021

I can not reproduce this error on my local build. As @babel/node should pass through all V8 options including --max-old-space-size:

flag === "debug" || // node debug foo.js
flag === "inspect" ||
v8Flags.indexOf(getNormalizedV8Flag(flag)) >= 0 ||
process.allowedNodeEnvironmentFlags.has(flag)
) {
args.unshift(arg);

You can add the following snippets

console.log(process.argv[0], args);
throw new Error("exit");

before

Can you attach your log output after you edit node_modules/@babel/node/lib/babel-node?

@ryancat
Copy link
Author

ryancat commented Jan 14, 2021

@JLHwung Thanks for looking into this. I used htop to check my code and found the --max_old_space_size option is passed down in cluster correctly. However, it's not respected by the child process and they would run out of memory regardless of that option.

The example code on repl.it that I linked in the issue do not have @babel/node and @babel/core dependencies. However this could be easily reproduced if you copy them to local folder, run yarn add @babel/node and yarn add @babel/core, then run

node node_modules/@babel/node/bin/babel-node.js --max_old_space_size=4096 runCluster.js

You will notice the code failed with OOM exceptions. If you run the same script use node by itself, it works.

node --max_old_space_size=4096 runCluster.js

@JLHwung
Copy link
Contributor

JLHwung commented Jan 15, 2021

Okay I can reproduce the error. Instead of testing --max_old_space_size=4096 which may have platform dependent behaviour, we can test --expose_gc and check whether gc is defined in the forked process.

@JLHwung
Copy link
Contributor

JLHwung commented Jan 15, 2021

Posted an upstream issue nodejs/node#36948 as I can't figure out how to fix it on Babel side. As a workaround mentioned by OP, please use NODE_OPTIONS=(...supported v8 options) when running @babel/node.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Apr 20, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: node
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants