Nuxt.js: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

Created on 14 Jun 2019  ยท  11Comments  ยท  Source: nuxt/nuxt.js

Version

v2.8.1

Reproduction link

https://codesandbox.io/s/github/nuxt/codesandbox-nuxt/tree/master/?fontsize=14

Steps to reproduce

  1. yarn create nuxt-app demo.
  2. yarn dev
  3. ab -n 1000 -c 100 http://127.0.0.1:3000/. Try a few times, the memory is more than 1G

What is expected ?

To release memory no longer grows.

What is actually happening?

```html
<--- Last few GCs --->

[44646:0x10264a000] 149203 ms: Mark-sweep 1235.2 (1425.2) -> 1234.5 (1425.7) MB, 1168.9 / 0.1 ms (average mu = 0.097, current mu = 0.043) allocation failure scavenge might not succeed
[44646:0x10264a000] 149305 ms: Scavenge 1237.1 (1426.7) -> 1235.9 (1427.7) MB, 6.8 / 0.0 ms (average mu = 0.097, current mu = 0.043) allocation failure

<--- JS stacktrace --->

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

0: ExitFrame [pc: 0x250efdd5be3d]
1: StubFrame [pc: 0x250efdd0d608]
2: StubFrame [pc: 0x250efe0e5e4c]

Security context: 0x07356d99e6e9
3: /* anonymous */ [0x735c23da299] [server.js:2134] [bytecode=0x735dd7c4c49 offset=221](this=0x0735c23da2d9 ,exports=0x0735c23da2d9 ,require=0x0735c23da331

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x10003c597 node::Abort() [/usr/local/bin/node]
2: 0x10003c7a1 node::OnFatalError(char const, char const) [/usr/local/bin/node]
3: 0x1001ad575 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate, char const, bool) [/usr/local/bin/node]
4: 0x100579242 v8::internal::Heap::FatalProcessOutOfMemory(char const) [/usr/local/bin/node]
5: 0x10057bd15 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [/usr/local/bin/node]
6: 0x100577bbf v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
7: 0x100575d94 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
8: 0x10058262c v8::internal::Heap::AllocateRawWithLigthRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
9: 0x1005826af v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x100551ff4 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/bin/node]
11: 0x1007da044 v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object
, v8::internal::Isolate) [/usr/local/bin/node]
12: 0x250efdd5be3d
```

This bug report is available on Nuxt community (#c9359)
bug-report stale

Most helpful comment

@manniL meet in the production too

All 11 comments

Memory leaks in dev mode can't be avoided. They don't appear in prod mode though, except through userland code .

@manniL meet in the production too

Actually, I managed to trigger this using yarn generate:

```~/P/w/frontend โฏโฏโฏ yarn generate master โฌ† โœš โœฑ โžœ
yarn run v1.19.1
$ nuxt-ts generate
โ„น Production build 10:19:58
โœ” Builder initialized 10:19:58
โœ” Nuxt files generated 10:19:58
โ„น Starting type checking service... nuxt:typescript 10:19:59
โ„น Using 4 workers with 4096MB memory limit nuxt:typescript 10:19:59

โ— Client โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ emitting (95%) vue-client-plugin

โ—ฏ Server

<--- Last few GCs --->
tep 16.2 ms, walltime since start of marking 55 ms) (average mu = 0.292, current mu = 0.245) finalize i[79389:0x33c0150] 541309 ms: Mark-sweep 2047.4 (2059.7) -> 2042.3 (2054.4) MB, 15.2 / 0.0 ms (+ 30.9 ms in 33 steps since start of marking, biggest step 11.8 ms, walltime since start of marking 52 ms) (average mu = 0.217, current mu = 0.131) finalize i[79389:0x33c0150] 541322 ms: Scavenge 2043.5 (2054.4) -> 2042.3 (2060.9) MB, 2.7 / 0.0 ms (average mu = 0.217, current mu = 0.131) allocation failure

<--- JS stacktrace --->

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

0: ExitFrame [pc: 0x13a71b9]

Security context: 0x3a4b48f408d1
1: /* anonymous /(aka / anonymous */) [0x19ede8afa709] [/home/js/PIRC/website/frontend/node_modules/babel-code-frame/lib/index.js:~124] pc=0x22705b233297
2: arguments adaptor frame: 16->0
3: StubFrame [pc: 0x13e36ed]
4: replace [0x3a4b48f563c1](this=0x29d212600119

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x9ef190 node::Abort() [/home/js/.nvm/versions/node/v12.16.1/bin/node]
2: 0x9f13b2 node::OnFatalError(char const, char const) [/home/js/.nvm/versions/node/v12.16.1/bin/node]
3: 0xb5da9e v8::Utils::ReportOOMFailure(v8::internal::Isolate, char const, bool) [/home/js/.nvm/versions/node/v12.16.1/bin/node]
4: 0xb5de19 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate, char const, bool) [/home/js/.nvm/versions/node/v12.16.1/bin/node]
5: 0xd0a765 [/home/js/.nvm/versions/node/v12.16.1/bin/node]
6: 0xd0adf6 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/home/js/.nvm/versions/node/v12.16.1/bin/node]
7: 0xd1760a v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/home/js/.nvm/versions/node/v12.16.1/bin/node]
8: 0xd18515 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/home/js/.nvm/versions/node/v12.16.1/bin/node]
9: 0xd19bbf v8::internal::Heap::HandleGCRequest() [/home/js/.nvm/versions/node/v12.16.1/bin/node]
10: 0xcc8715 v8::internal::StackGuard::HandleInterrupts() [/home/js/.nvm/versions/node/v12.16.1/bin/node]
11: 0x1024376 v8::internal::Runtime_StackGuard(int, unsigned long, v8::internal::Isolate) [/home/js/.nvm/versions/node/v12.16.1/bin/node]
12: 0x13a71b9 [/home/js/.nvm/versions/node/v12.16.1/bin/node]
error Command failed with signal "SIGABRT".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```

@samupl
How did you solve this problem?

@AntonBazarov

I'm not sure if this is a bug in nuxtjs or webpack, BUT in my case I narrowed it down to having the dist/ directory present.

If there IS a dist/ directory existing at the time I run yarn generate, randomly it will fail with the error above.
If I remove the dist directory prior to running yarn generate, the problem never appeared.

Now I don't have any statistics, but I have my builds running in docker containers, at build time. I made sure to add dist/ to .dockerignore, and now nobody complains about this error anymore.

So - check if you have a dist/ directory. If you do, remove it and see if it helps in your case as well.

@manniL: Can this issue be reopened? I've managed to trigger this bug (see my comment above) on a fresh nuxt.js installation.

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as pending will not be automatically marked as stale.

Currently stuck on this on a fresh install of nuxt... Is nuxt officially broken?

For anyone having this issue, please try my solution https://github.com/nuxt-community/auth-module/issues/286#issuecomment-615907089

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as pending will not be automatically marked as stale.

I am facing the same problem. In my case the problem lies in the following auth configuration. It happens on a fresh installation of nuxt:2.14.3, and so it should be easy to reproduce the error.
I am using @nuxt/auth-next:^5.0.0-1595976864.509d9d6

Is the token 'cookie' being repeated twice causing an infinite loop?

// nuxt.config.js
auth: {
    strategies: {
      cookie: {
        cookie: {
          name: 'session',
        },
        endpoints: {
            login: { url: '/api/login', method: 'post' },
            logout: { url: '/api/logout', method: 'post' }
        }
      }
    }
 },
Was this page helpful?
0 / 5 - 0 ratings

Related issues

lazycrazy picture lazycrazy  ยท  3Comments

bimohxh picture bimohxh  ยท  3Comments

shyamchandranmec picture shyamchandranmec  ยท  3Comments

mikekidder picture mikekidder  ยท  3Comments

jaredreich picture jaredreich  ยท  3Comments