Azure / autorest

OpenAPI (f.k.a Swagger) Specification code generator. Supports C#, PowerShell, Go, Java, Node.js, TypeScript, Python
MIT License
4.61k stars 737 forks source link

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory #4158

Closed marche0133 closed 3 years ago

marche0133 commented 3 years ago

Describe the bug

After a recent install of npm and node, the autorest javascript and autorest java does not work. I tried to increase the memory by --max-memory-size=3888 but does not work.

npm 6.14.13 node v14.17.0 autorest 3.2.3

autorest packages image

E:\WebstormProjects\azure-sdk-for-js-pr\sdk\communication\communication-router>npm run build:autorest

> @azure/communication-router@1.0.0-beta.7 build:autorest E:\WebstormProjects\azure-sdk-for-js-pr\sdk\communication\communication-router
> autorest ./swagger/README.md --typescript --version=3.0.6267 --v3 --package-version=1.0.0-beta.5 && rushx format

AutoRest code generation utility [cli version: 3.2.3; node: v14.17.0, max-memory: 1024 MB]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
   Loading AutoRest core      'C:\Users\marcma\.autorest\@autorest_core@3.0.6267\node_modules\@autorest\core\dist' (3.0.6267)
   Loading AutoRest extension '@autorest/typescript' (6.0.0-dev.20210114.1->6.0.0-dev.20210114.1)
   Loading AutoRest extension '@autorest/modelerfour' (4.15.442->4.15.442)
   Loading AutoRest extension '@autorest/modelerfour' (4.15.448->4.15.448)

<--- Last few GCs --->

[14876:03DA7FF8]       81 ms: Mark-sweep 1.0 (3.5) -> 1.0 (3.5) MB, 1.4 / 0.0 ms  (average mu = 0.590, current mu = 0.191) allocation failure GC in old space requested
[14876:03DA7FF8]       83 ms: Mark-sweep (reduce) 1.0 (3.5) -> 1.0 (3.5) MB, 1.1 / 0.0 ms  (average mu = 0.492, current mu = 0.230) last resort GC in old space requested
[14876:03DA7FF8]       84 ms: Mark-sweep (reduce) 1.0 (2.5) -> 1.0 (3.5) MB, 1.5 / 0.0 ms  (average mu = 0.316, current mu = 0.020) last resort GC in old space requested

<--- JS stacktrace --->

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
Process() cancelled due to failure
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @azure/communication-router@1.0.0-beta.7 build:autorest: `autorest ./swagger/README.md --typescript --version=3.0.6267 --v3 --package-version=1.0.0-beta.5 && rushx format`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @azure/communication-router@1.0.0-beta.7 build:autorest script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\marcma\AppData\Roaming\npm-cache\_logs\2021-06-08T16_45_10_763Z-debug.log
E:\StudioProjects\autorest.java>E:\StudioProjects\azure-sdk-for-android\sdk\communication\azure-communication-chat\swagger\README.md^Z

E:\StudioProjects\autorest.java>autorest E:\StudioProjects\azure-sdk-for-android\sdk\communication\azure-communication-chat\swagger\README.md --java --v4 --use=@autorest/java@4.0.11
AutoRest code generation utility [cli version: 3.2.3; node: v14.17.0, max-memory: 1024 MB]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
NOTE: AutoRest core version selected from configuration: ~3.1.0.
   Loading AutoRest core      'C:\Users\marcma\.autorest\@autorest_core@3.1.3\node_modules\@autorest\core\dist' (3.1.3)
INFORMATION: > Loading AutoRest extension '@autorest/java' (4.0.11->4.0.11)
INFORMATION: > Loading local AutoRest extension '@autorest/java.vanilla' (C:\Users\marcma\.autorest\@autorest_java@4.0.11\node_modules\@autorest\java\javagen)
INFORMATION: > Loading local AutoRest extension '@autorest/java.preprocessor' (C:\Users\marcma\.autorest\@autorest_java@4.0.11\node_modules\@autorest\java\javagen\..\preprocessor)
INFORMATION: > Loading local AutoRest extension '@autorest/java.postprocessor' (C:\Users\marcma\.autorest\@autorest_java@4.0.11\node_modules\@autorest\java\javagen\..\postprocessor)
INFORMATION: > Loading AutoRest extension '@autorest/modelerfour' (4.15.447->4.15.447)

<--- Last few GCs --->

[17616:04168D88]      252 ms: Mark-sweep 1.0 (3.5) -> 1.0 (3.5) MB, 3.3 / 0.0 ms  (average mu = 0.650, current mu = 0.254) allocation failure GC in old space requested
[17616:04168D88]      256 ms: Mark-sweep (reduce) 1.0 (3.5) -> 1.0 (3.5) MB, 2.6 / 0.0 ms  (average mu = 0.556, current mu = 0.238) last resort GC in old space requested
[17616:04168D88]      260 ms: Mark-sweep (reduce) 1.0 (2.5) -> 1.0 (3.5) MB, 4.1 / 0.0 ms  (average mu = 0.364, current mu = 0.011) last resort GC in old space requested

<--- JS stacktrace --->

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
Process() cancelled due to failure


**Expected behavior**
It should run and parse the swagger.

**Additional context**
It throws a out of memory error.
timotheeguerin commented 3 years ago

Did you try using NODE_OPTIONS environment variable with a value of --max-old-space-size=4096

marche0133 commented 3 years ago

Did you try using NODE_OPTIONS environment variable with a value of --max-old-space-size=4096

Yes, I tried to set it in ide.

image

timotheeguerin commented 3 years ago

Feel like the IDE might just set the env variable for the npm script that trigger the autorest build and not the autorest process. Can you double check with setting as an environment variable. If it was set correctly autorest will log the node memory allowed

AutoRest code generation utility [cli version: 3.2.3; node: v14.16.0, max-memory: 16384 MB]
marche0133 commented 3 years ago

Hi, I upgrade Node to latest version v16 and delete npm and npm-cache folder in roaming, the autorest works now.