pulumi: Nodejs >v18 throws exception

What happened?

Upgrading my dependencies to latest, pulled in Azure Native v2.47.0 and builds were all failing. I thought this was due to my changes but removing my changes still caused failures.

Downgrading and pinning to 2.46.0 fixed all issues

image

Example

resourceGroupName: `rg-${suffix}`,
    location: 'centralus',
});

// TODO figure out how to handle password if we intend to do those
const sqlServer = new azureNative.sql.Server(
    `sql-${pulumi.getStack()}`,
    {
        serverName: `${suffix}`,
        resourceGroupName: resourceGroup.name,
        location: resourceGroup.location,
        administratorLogin: ######
        administratorLoginPassword: #######
        publicNetworkAccess: ServerPublicNetworkAccessFlag.Enabled,
        restrictOutboundNetworkAccess: ServerNetworkAccessFlag.Disabled,
        // minimalTlsVersion: '1.2',

        version: '12.0',
    },
    { parent: resourceGroup },
);

Output of pulumi about

This was running via github action but i can run again to verify versions if needed

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you’ve opened one already).

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 23 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Thank you everyone for the additional information. I was able to reproduce this in Github Actions. After patching out our usage of the debugger API (which is what is showing up in the original stack traces), I get a much more familiar stack trace:

    pulumi:pulumi:Stack (pulumi-16596-repro-prod):
      <--- Last few GCs --->
      [1801:0x62c2d70]    32167 ms: Scavenge (reduce) 2045.5 (2080.9) -> 2045.0 (2081.2) MB, 18.84 / 0.00 ms  (average mu = 0.098, current mu = 0.003) allocation failure;
      [1801:0x62c2d70]    33511 ms: Mark-Compact (reduce) 2045.8 (2081.2) -> 2045.2 (2081.7) MB, 1341.76 / 0.00 ms  (average mu = 0.066, current mu = 0.034) allocation failure; scavenge might not succeed
      <--- JS stacktrace --->
      FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
      ----- Native stack trace -----
       1: 0xb80c78 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [/opt/hostedtoolcache/node/20.15.0/x64/bin/node]
       2: 0xeee1b0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/opt/hostedtoolcache/node/20.15.0/x64/bin/node]
...

We’re running out of memory! Given that it does not fail 100% of the time, we must be right on the edge of the limit. Small internal changes in Nodejs in more recent versions might push us over the edge more often.

Nodejs configures the default limit for the heap based on the system it’s running on. I remember this heuristic having occasionally changed in the past.

Github Actions runners have 7GB of memory for private repos, and 16GB for public repos https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories, so if you run in a public repo you are unlikely to hit the issue (heap defaults to 4GB on these, vs 2GB on private runners).

Additionally, in containerised environments, this tries to take into account the available memory for the container, as opposed to total system memory. However this detection does not always work, for example older versions of nodejs (before 20.x) don’t detect container memory limits when using cgroups v2 https://github.com/nodejs/node/issues/47259. This was fixed in Nodejs 20.

docker run --rm -it --memory 7168m node:18 node -e 'console.log(require("v8").getHeapStatistics().heap_size_limit)'
> 4345298944
docker run --rm -it --memory 7168m node:20 node -e 'console.log(require("v8").getHeapStatistics().heap_size_limit)'
> 2197815296

docker run --rm -it --memory 16384m node:18 node -e 'console.log(require("v8").getHeapStatistics().heap_size_limit)'
> 4345298944
docker run --rm -it --memory 16384m node:20 node -e 'console.log(require("v8").getHeapStatistics().heap_size_limit)'
> 4345298944

The result is that when running with Nodejs 20 in a containerised environment like Kubernetes, we have less memory available for the heap. Since the azure provider is very large, we run into the limit.

Workaround

To work around all of this, you can explicitly set the heap size for Nodejs in Pulumi.yaml

runtime:
  name: nodejs
  options:
    nodeargs: --max-old-space-size=4096

This issue has been addressed in PR #16700 and shipped in release v3.127.0.

@julienp thanks a lot for the thorough investigation and the clear explanation. Given the cryptic error message and the increased risk of bumping onto this issue, is there anything we should do to 1) try to mitigate this issue without user intervention? and 2) increase awareness and visibility so people find the workaround you proposed more easily?