Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
devhyunjae opened this issue Oct 10, 2018 · 18 comments
Labels
please add a complete reproduction Please add a complete reproduction.

Comments

@devhyunjae
Copy link

Bug report

Describe the bug

If I run the dev server and turn on like few hours. The server automatically shuts down with this error message.

<--- Last few GCs --->

[42587:0x102801e00]  4108743 ms: Mark-sweep 1369.0 (1417.2) -> 1369.0 (1421.2) MB, 558.5 / 0.0 ms  allocation failure GC in old space requested
[42587:0x102801e00]  4109472 ms: Mark-sweep 1369.0 (1421.2) -> 1369.0 (1413.2) MB, 729.2 / 0.0 ms  last resort GC in old space requested
[42587:0x102801e00]  4109969 ms: Mark-sweep 1369.0 (1413.2) -> 1369.0 (1413.2) MB, 497.1 / 0.0 ms  last resort GC in old space requested


<--- JS stacktrace --->

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

Security context: 0x19c4f6125879 <JSObject>
    1: add [/Users/steve/juven/frontend/node_modules/hard-source-webpack-plugin/lib/SerializerAppend2.js:~71] [pc=0x1bb0948a8aa](this=0x19c4e8bde1f9 <WriteOutput map = 0x19c48d594f79>,key=0x19c4e32749c1 <String[61]: 1B2M2Y8AsgTpgAmY7PhCfg==node_modules/rc-animate/es/Animate.js>,content=0x19c4e8bb12e1 <Very long string[308078]>)
    2: write [/Users/steve/frontend/node_modules/hard-source-w...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 5: v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 6: v8::String::WriteUtf8(char*, int, int*, int) const [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 7: node::StringBytes::Write(v8::Isolate*, char*, unsigned long, v8::Local<v8::Value>, node::encoding, int*) [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 8: void node::Buffer::(anonymous namespace)::StringWrite<(node::encoding)1>(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 9: 0x1bb0710a5c7
10: 0x1bb0948a8aa
error Command failed with signal "SIGABRT".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

To Reproduce

Not sure. Just turn on the dev server for few hours

Expected behavior

Server should not be shut down

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: mac
  • Browser chrome
  • Version of Next.js: 7.0.0

Additional context

Add any other context about the problem here.

@timneutkens
Copy link
Member

Not sure what to do with this without a reproduction. So I'm going to close this issue.

@pruhstal
Copy link

FWIW I've also seen this on Next @7. It is a bit difficult to diagnose but I'm happy to share anything like my next.config or .babelrc.

@sasindroid
Copy link

Hi @pruhstal - Were you able to resolve this issue?

@james-gardner
Copy link

james-gardner commented Dec 17, 2018

Similar issue with latest next.js

RangeError: "size" argument must not be larger than 2147483647
    at Function.Buffer.allocUnsafe (buffer.js:253:3)
    at alloc (/Users/jamesgardner/src/project/app/node_modules/hard-source-webpack-plugin/lib/SerializerAppend2.js:46:17)
    at Append2._readFile (/Users/jamesgardner/src/project/app/node_modules/hard-source-webpack-plugin/lib/SerializerAppend2.js:160:14)
    at <anonymous>

<--- Last few GCs --->

[14301:0x103000000]     6211 ms: Mark-sweep 819.3 (832.0) -> 819.3 (831.0) MB, 57.0 / 0.0 ms  allocation failure GC in old space requested
[14301:0x103000000]     6252 ms: Mark-sweep 819.3 (831.0) -> 819.1 (828.0) MB, 40.8 / 0.0 ms  last resort GC in old space requested
[14301:0x103000000]     6278 ms: Mark-sweep 819.1 (828.0) -> 819.1 (828.0) MB, 26.7 / 0.0 ms  last resort GC in old space requested


<--- JS stacktrace --->

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

Security context: 0x35f55f7a5879 <JSObject>
    1: _readFile [/Users/jamesgardner/src/project/app/node_modules/hard-source-webpack-plugin/lib/SerializerAppend2.js:167] [bytecode=0x35f56c0d1b01 offset=422](this=0x35f521c59649 <Append2 map = 0x35f5ff291821>,file=0x35f5ebe02311 <the_hole>)
    2: /* anonymous */(this=0x35f52c504e39 <JSGlobal Object>,9)
    3: /* anonymous */(aka /* anonymous */)(this=0x35f5ebe022d1 <undefined...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/usr/local/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
 4: v8::internal::Factory::NewRawOneByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
 5: v8::internal::Factory::NewStringFromUtf8(v8::internal::Vector<char const>, v8::internal::PretenureFlag) [/usr/local/bin/node]
 6: v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::NewStringType, int) [/usr/local/bin/node]
 7: node::StringBytes::Encode(v8::Isolate*, char const*, unsigned long, node::encoding, v8::Local<v8::Value>*) [/usr/local/bin/node]
 8: void node::Buffer::(anonymous namespace)::StringSlice<(node::encoding)1>(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
 9: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) [/usr/local/bin/node]
10: v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/usr/local/bin/node]
11: v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/usr/local/bin/node]
12: 0x1e54124842fd
13: 0x1e541253d1d6

I used to get around this with npm clean cache --force but that's not working since I upgraded to the latest npm.

@pruhstal
Copy link

@sasindroid not yet, but I haven't been running the server that long enough to replicate lately. I'll post an update when it happens again.

@pruhstal
Copy link

@sasindroid happened again. @ ^7.0.2

<--- Last few GCs --->

[37728:0x102801000]  8389263 ms: Mark-sweep 1388.5 (1464.0) -> 1388.4 (1464.0) MB, 456.9 / 0.0 ms  allocation failure GC in old space requested
[37728:0x102801000]  8389805 ms: Mark-sweep 1388.4 (1464.0) -> 1388.4 (1431.0) MB, 541.7 / 0.0 ms  last resort GC in old space requested
[37728:0x102801000]  8390320 ms: Mark-sweep 1388.4 (1431.0) -> 1388.4 (1430.5) MB, 514.8 / 0.0 ms  last resort GC in old space requested


<--- JS stacktrace --->

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

Security context: 0xf9978125501 <JSObject>
    1: push(this=0xf990d40aef1 <JSArray[50855]>)
    2: /* anonymous */(aka /* anonymous */) [/Users/me/Sites/node_modules/@babel/core/lib/transformation/file/merge-map.js:~155] [pc=0x167f491c5acb](this=0xf9965f02201 <null>,m=0xf998df5b631 <Object map = 0xf997e2193e1>)
    3: arguments adaptor frame: 3->1
    4: forEach(this=0xf998ae06b79 <JSArray[89656]>)
    5: eachMapping(aka Sourc...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 2: node::FatalTryCatch::~FatalTryCatch() [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 4: v8::internal::Factory::NewUninitializedFixedArray(int) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 5: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::ConvertElementsWithCapacity(v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::FixedArrayBase>, v8::internal::ElementsKind, unsigned int, unsigned int, unsigned int, int) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 6: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::GrowCapacityAndConvertImpl(v8::internal::Handle<v8::internal::JSObject>, unsigned int) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 7: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::Add(v8::internal::Handle<v8::internal::JSObject>, unsigned int, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, unsigned int) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 8: v8::internal::JSObject::AddDataElement(v8::internal::Handle<v8::internal::JSObject>, unsigned int, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::ShouldThrow) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 9: v8::internal::Runtime_SetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
10: 0x167f3cb042fd
Abort trap: 6

Using "@babel/core": "^7.2.2" and "babel-core": "^7.0.0-bridge.0" and I have a hunch it's related to babel.

@qd-qd
Copy link

qd-qd commented Feb 20, 2019

Happened again in production environment.

@timneutkens
Copy link
Member

"Happened again in production environment." is not really actionable from our side. Please provide a reproduction so that we can investigate.

@ckeeney
Copy link

ckeeney commented Feb 26, 2019

After upgrading from NextJS 6 to NextJS 8, I was getting an out of memory error and the chrome dev tools memory tab indicated this was related to styled-components.

I isolated my occurrence of this issue to the usage of <Text is={Flex}/>, where both components come from rebass@v2.

Removing this usage solved my problem.

@timneutkens
Copy link
Member

@ckeeney
Copy link

ckeeney commented Feb 27, 2019

It sure is. Thanks.

@timneutkens
Copy link
Member

👌

@ajhool
Copy link

ajhool commented Mar 11, 2019

Seeing the same issue. The common node.js solution appears to be using a

--max-old-space-size

flag on the build. How can that flag be injected into the now build?

@brothatru
Copy link

You can do it by setting NODE_OPTIONS.

ie)

"script": {
  "build": "NODE_OPTIONS=--max_old_space_size=4096 next build"
}

Had to dig through like 40-50 webpages to solve this damn "out of memory" problem and figure out how to give node more memory via npm scripts.

Also going to note, this wasn't happening on my local macbook (16gb ram). However, kept running into this issue on our jenkin's t2.medium ec2 instance (only 4gb of ram).

Resources - npm/npm#12238 (comment)

You're welcome codestas'

@impactcolor
Copy link

impactcolor commented Apr 10, 2020

@brothatru I'm trying to do this and still run out of memory on a mac any ideas what I'm missing? scripts": { "dev": "NODE_OPTIONS=--max_old_space_size=8096 npm run development", }

@ali-ehsan
Copy link

ali-ehsan commented Jul 10, 2020

It is still happening in Next 9 in both dev and prod. Increasing max_old_space_size is not a solution. Why does node take up so much memory?

@PLQin
Copy link

PLQin commented Jul 22, 2020

Maybe your code isn't efficient , or maybe you're quoting util that doesn't work, or caused by improper reference/use ;
But more often, it's because of node_modules (for example, hard-source-webpack-plugin) 。
That's what's causing your memory to get used up 。

solution :

  • find out why it's taking up memory and fix it (node_modules or code that creates an endless loop for example)。
  • set max_old_space_size

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
please add a complete reproduction Please add a complete reproduction.
Projects
None yet
Development

No branches or pull requests