Azure / autorest.csharp

Extension for AutoRest (https://github.com/Azure/autorest) that generates C# code
MIT License
140 stars 160 forks source link

JavaScript heap out of memory error when using --legacy #4885

Open PerryCodes opened 1 week ago

PerryCodes commented 1 week ago

I'm trying to use the --legacy option and it generates the following error:


AutoRest code generation utility [cli version: 3.7.1; node: v12.19.1]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
info    | AutoRest core version selected from configuration: ~2.0.4413.
   Loading AutoRest core      'C:\Users\jperr\.autorest\@microsoft.azureautorest-core@2.0.4429\nodemodules\@microsoft.azure\autorest-core\dist' (2.0.4429)
   Loading AutoRest extension '@microsoft.azure/autorest.csharp' (~2.3.79->2.3.102)
   Loading AutoRest extension '@microsoft.azure/autorest.modeler' (2.3.55->2.3.55)

<--- Last few GCs --->
3)[42072:000001E712DE7150]   379828 ms: Mark-sweep 2040.9 (2063.6) -> 2039.2 (2065.4) MB, 1301.0 / 0.0 ms  (+ 320.0 ms in 70 steps since start of marking, biggest step 11.5 ms, walltime since start of marking 1638 ms) (average mu = 0.118, current mu = 0.010[42072:000001E712DE7150]   381525 ms: Mark-sweep 2042.6 (2065.4) -> 2041.4 (2066.9) MB, 1447.3 / 0.0 ms  (+ 237.5 ms in 55 steps since start of marking, biggest step 7.0 ms, walltime since start of marking 1697 ms) (average mu = 0.063, current mu = 0.007)

<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 00007FF68A7F994D]
Security context: 0x035ec77408d1 <JSObject>
    1: ParseNodeInternal(aka ParseNodeInternal) [00000077DB880801] [C:\Users\jperr\.autorest\@microsoft.azure_autorest-core@2.0.4429\node_modules\@microsoft.azure\autorest-core\dist\lib\ref\yaml.js:~87] [pc=000002DB0E4A4DF9](this=0x0142f73404b1 <undefined>,0x027f2cb3e871 <Object map = 000001F57D71FC49>,0x03d30a1f3431 <Object map = 000002EDC19FE1E9>,0x03580...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF689BC035F napi_wrap+119615
 2: 00007FF689B67666 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NextTableOffset+38102
 3: 00007FF689B68466 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NextTableOffset+41686
 4: 00007FF68A3A451E v8::Isolate::ReportExternalAllocationLimitReached+94
 5: 00007FF68A38C6C1 v8::SharedArrayBuffer::Externalize+833
 6: 00007FF68A23DE9C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1436
 7: 00007FF68A2490E0 v8::internal::Heap::ProtectUnprotectedMemoryChunks+1312
 8: 00007FF68A245BF4 v8::internal::Heap::PageFlagsAreConsistent+3204
 9: 00007FF68A23B3F3 v8::internal::Heap::CollectGarbage+1283
10: 00007FF68A239A64 v8::internal::Heap::AddRetainedMap+2500
11: 00007FF68A25ADAD v8::internal::Factory::NewFillerObject+61
12: 00007FF689FBE381 v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+1665
13: 00007FF68A7F994D v8::internal::SetupIsolateDelegate::SetupHeap+546925
14: 000002DB0E4A4DF9
PerryCodes commented 1 week ago

Can an admin please remove the v3 label? I didn't realize that --legacy was bumping the version of autorest.csharp down to v2 until after posting this. Thanks.

PerryCodes commented 1 week ago

Here's the spec I'm attempting to build a client for (Autotask PSA) v1.json

I'm able to build clients fine without --legacy, however it doesn't seem to bother with models anymore. So then I tried the --generation1-convenience-client option. That built models, but also decided it wanted to scope internal all over the clients.

increase-memory-limit didn't help.

lirenhe commented 5 days ago

Could you try the customization to make clients internal? https://github.com/Azure/autorest.csharp/blob/feature/v3/readme.md#make-a-client-internal

ArcturusZhang commented 4 days ago

Hi @PerryCodes --legacy should be using our v2 generator which has been retired for a long time. node has some configuration which allows you to enlarge the heap, such as --max-old-space-size=4096. The OOM error might happen when your swagger is big.

But in general, our recommendation is to switch to the v3 generator, and if possible, switch to typespec.

ArcturusZhang commented 4 days ago

Here's the spec I'm attempting to build a client for (Autotask PSA) v1.json

I'm able to build clients fine without --legacy, however it doesn't seem to bother with models anymore. So then I tried the --generation1-convenience-client option. That built models, but also decided it wanted to scope internal all over the clients.

increase-memory-limit didn't help.

So if you remove --legacy, only typespec input will generate models. If you remove --legacy and add --generation1-convenience-client option, and you want the clients to be public, you could add another configuration --public-client with the --generation1-convenience-client. The public-client configuration should make your clients to be public by default.