question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Heap limit Allocation failed/JavascriptHeap out of memory

See original GitHub issue

When using hardhat to compile contracts/generate typescript, after the compilation finishes successfully typechain hangs for several seconds before running out of memory.

The most recent addition to the code were some nested Structs (no more than 2 levels), though I’ve never run into any issues like this before, and definitely no recursive structs.

reinstalling (purging node_modules) did not change the result.

Compilation finished successfully
Creating Typechain artifacts in directory typechain for target ethers-v5

<--- Last few GCs --->

[3314:0x7fe0d0008000]    43338 ms: Mark-sweep 4056.1 (4134.2) -> 4052.1 (4134.2) MB, 3081.8 / 0.0 ms  (average mu = 0.184, current mu = 0.041) allocation failure scavenge might not succeed
[3314:0x7fe0d0008000]    47172 ms: Mark-sweep 4068.0 (4134.4) -> 4063.9 (4159.1) MB, 3795.3 / 0.0 ms  (average mu = 0.092, current mu = 0.010) allocation failure scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0x1100c4515 node::Abort() (.cold.1) [/usr/local/bin/node]
 2: 0x10edc5989 node::Abort() [/usr/local/bin/node]
 3: 0x10edc5aff node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 4: 0x10ef452c7 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 5: 0x10ef45263 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 6: 0x10f0e6975 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
 7: 0x10f0e52fc v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
 8: 0x10f0f1af0 v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
 9: 0x10f0f1b71 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x10f0becc7 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/usr/local/bin/node]
11: 0x10f47449e v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
12: 0x10f81ddd9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
error Command failed with signal "SIGABRT".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
krzkaczorcommented, Nov 21, 2021

@DominicRomanowski thank you! This is a great repro. It will be fixed this week 😃

2reactions
0xdomromcommented, Nov 20, 2021
pragma solidity 0.7.6;
pragma experimental ABIEncoderV2;


library Observer {

  struct Observation {
    int val;
    uint blockTimestamp;
  }

  function write(
    Observation[65535] storage self,
    uint16 index,
    uint newVal,
    uint blockTimestamp
  ) internal returns (uint16 indexUpdated) { }
}



contract TestTypechain {
  using Observer for Observer.Observation[65535];

  struct ObservationParams {
    Observer.Observation[65535] observations;
    uint16 index;
  }

  struct Bar {
    ObservationParams fooObservations;
  }

  mapping(uint => Bar) public bars;

  function makeObservation(uint barId, uint newVal) external {
    Bar storage bar = bars[barId];
    bar.fooObservations.index = bar.fooObservations.observations.write(bar.fooObservations.index, newVal, block.timestamp);
  }
}

Heya, I was able to isolate the issue; Removing the size limit (65535) on the array allowed the typechain to compile

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix JavaScript Heap Out of Memory Error
A common problem while working on a JavaScript Node.js project is the “JavaScript heap out of memory” error. This error usually occurs when ......
Read more >
JavaScript heap out of memory
This generally occurs on larger projects where the default amount of memory allocated by Node (1.5gb) is insufficient to complete the command successfully....
Read more >
How to solve JavaScript heap out of memory error
To fix JavaScript heap out of memory error, you need to add the --max-old-space-size option when running your npm command. ... Alternatively, you ......
Read more >
Node.js heap out of memory - javascript
If I remember correctly, there is a strict standard limit for the memory usage in V8 of around 1.7 GB, if you do...
Read more >
JavaScript Heap Out Of Memory Error
How to solve the “Heap out of memory” error in JavaScript ... 4096 translates to 4 GB of memory. You can set the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found