Nuxt.js: Production memory loss crashes - suggested high priority

Created on 20 Sep 2017  路  73Comments  路  Source: nuxt/nuxt.js

This is a duplicate issue of #1678 since it was closed and mistakened as some js-beautify issue

None of my nuxtjs production environments last more than 39-40hrs. This is the ballpark moment where nuxt/vue seems to crash.

This happens on AWS instance running the Amazon Linux AMI with node v8.3.0

The original crash:

running `HOST=0.0.0.0 nuxt start I get

<--- Last few GCs --->

[8202:0x2822f10] 148084153 ms: Mark-sweep 1399.9 (1494.4) -> 1399.9 (1494.4) MB, 2284.2 / 0.0 ms  allocation failure GC in old space requested
[8202:0x2822f10] 148086478 ms: Mark-sweep 1399.9 (1494.4) -> 1399.9 (1494.4) MB, 2323.0 / 0.0 ms  last resort
[8202:0x2822f10] 148088794 ms: Mark-sweep 1399.9 (1494.4) -> 1399.9 (1494.4) MB, 2315.4 / 0.0 ms  last resort


<--- JS stacktrace --->

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

Security context: 0x37a56a69cca1 <JSObject>
    1: initWatch(aka initWatch) [/home/ec2-user/api/web/node_modules/vue/dist/vue.runtime.common.js:~3296] [pc=0x16c066f78f0b](this=0x37a56a682241 <undefined>,vm=0x361f52ccf229 <Vue$3 map = 0x3a932c4ded49>,watch=0x1374913debb1 <Object map = 0x25ca00203649>)
    2: _init [/home/ec2-user/api/web/node_modules/vue/dist/vue.runtime.common.js:~4181] [pc=0x16c06696451c](this=0x361f52ccf229 <Vue$3 map =...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x136916c [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewTransitionArray(int) [node]
 6: v8::internal::TransitionArray::Insert(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Map>, v8::internal::SimpleTransitionFlag) [node]
 7: v8::internal::Map::CopyReplaceDescriptors(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal::Handle<v8::internal::LayoutDescriptor>, v8::internal::TransitionFlag, v8::internal::MaybeHandle<v8::internal::Name>, char const*, v8::internal::SimpleTransitionFlag) [node]
 8: v8::internal::Map::CopyAddDescriptor(v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [node]
 9: v8::internal::Map::CopyWithField(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Representation, v8::internal::TransitionFlag) [node]
10: v8::internal::Map::TransitionToDataProperty(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Object::StoreFromKeyed) [node]
11: v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::StoreFromKeyed) [node]
12: v8::internal::StoreIC::LookupForWrite(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
13: v8::internal::StoreIC::UpdateCaches(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
14: v8::internal::StoreIC::Store(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
15: v8::internal::Runtime_StoreIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [node]
16: 0x16c0667840dd
Done in 148089.23s.

And again today

yarn start v0.27.5
$ HOST=0.0.0.0 nuxt start

 OPEN  http://localhost:3000

control-settings
control-settings
control-images

<--- Last few GCs --->

[16624:0x2b58f10] 143724943 ms: Mark-sweep 1400.0 (1486.9) -> 1400.0 (1486.9) MB, 2268.4 / 0.0 ms  allocation failure GC in old space requested
[16624:0x2b58f10] 143726690 ms: Mark-sweep 1400.0 (1486.9) -> 1400.0 (1486.9) MB, 1746.2 / 0.0 ms  last resort
[16624:0x2b58f10] 143728669 ms: Mark-sweep 1400.0 (1486.9) -> 1400.0 (1486.9) MB, 1979.9 / 0.0 ms  last resort


<--- JS stacktrace --->

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

Security context: 0x10cc8381cca1 <JSObject>
    2: $watch [/home/ec2-user/api/web/node_modules/vue/dist/vue.runtime.common.js:3362] [bytecode=0xa9573cc5771 offset=58](this=0x3374d9153869 <Vue$3 map = 0x16794112bb81>,expOrFn=0x27709a2361b1 <String[8]: nuxt.err>,cb=0x3374d91549f9 <JSFunction boundFn (sfi = 0xa9573cc3f21)>,options=0x3374d9154ca9 <Object map = 0x13ee4d484829>)
    4: createWatcher(aka createWatcher) [/home/ec2-user/api/web/no...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x136916c [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewTransitionArray(int) [node]
 6: v8::internal::TransitionArray::Insert(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Map>, v8::internal::SimpleTransitionFlag) [node]
 7: v8::internal::Map::CopyReplaceDescriptors(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal::Handle<v8::internal::LayoutDescriptor>, v8::internal::TransitionFlag, v8::internal::MaybeHandle<v8::internal::Name>, char const*, v8::internal::SimpleTransitionFlag) [node]
 8: v8::internal::Map::CopyAddDescriptor(v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [node]
 9: v8::internal::Map::CopyWithField(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Representation, v8::internal::TransitionFlag) [node]
10: v8::internal::Map::TransitionToDataProperty(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Object::StoreFromKeyed) [node]
11: v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::StoreFromKeyed) [node]
12: v8::internal::StoreIC::LookupForWrite(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
13: v8::internal::StoreIC::UpdateCaches(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
14: v8::internal::StoreIC::Store(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
15: v8::internal::Runtime_StoreIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [node]
16: 0x2007965840dd
Done in 143729.38s.

This bug report is available on Nuxt.js community (#c1519)
bug-confirmed help-wanted pending-repro

Most helpful comment

When all these tasks will be done: https://trello.com/b/lgy93IOl/nuxtjs-10

Should be at the end of the month

All 73 comments

I also opened an issue on vue.js which was immediately closed, but I have a feeling this might be somewhat tied into having/creating watchers for more than 40hrs:

https://github.com/vuejs/vue/issues/6656

Hi @acidjazz. There was a known issue with asyncData which should be resolved with latest versions of Nuxt. Also i think this bug is with one of 3rd party plugins you are using. We are using nuxt (w/ watch and SSR) in production and there is not memory leaks.

BTW we need more details to find exact problem. There are some tips for proper memory leak bugs here: https://github.com/nuxt/nuxt.js/issues/805

@pi0 thanks, i'm currently not using asyncData just yet in this environment, I'll keep reporting my crashes and doing what I can to help resolve this though

Here is another repro

[31211:0x38a6f10] 146854394 ms: Mark-sweep 1400.0 (1488.4) -> 1400.0 (1488.4) MB, 2293.6 / 0.0 ms  allocation failure GC in old space requested
[31211:0x38a6f10] 146856186 ms: Mark-sweep 1400.0 (1488.4) -> 1400.0 (1488.4) MB, 1791.3 / 0.0 ms  last resort
[31211:0x38a6f10] 146858242 ms: Mark-sweep 1400.0 (1488.4) -> 1400.0 (1488.4) MB, 2056.0 / 0.0 ms  last resort


<--- JS stacktrace --->

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

Security context: 0x2eb565e9cca1 <JSObject>
    2: $watch [/home/ec2-user/api/web/node_modules/vue/dist/vue.runtime.common.js:3362] [bytecode=0xae770f52f71 offset=58](this=0x211ad76df1e9 <Vue$3 map = 0x35f2c8a41709>,expOrFn=0x12dac85c4bb9 <String[8]: nuxt.err>,cb=0x71f1eb981d9 <JSFunction boundFn (sfi = 0xae770f51721)>,options=0xc25437f5b1 <Object map = 0xc835bc04829>)
    4: createWatcher(aka createWatcher) [/home/ec2-user/api/web/node_m...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x136916c [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewTransitionArray(int) [node]
 6: v8::internal::TransitionArray::Insert(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Map>, v8::internal::SimpleTransitionFlag) [node]
 7: v8::internal::Map::CopyReplaceDescriptors(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal::Handle<v8::internal::LayoutDescriptor>, v8::internal::TransitionFlag, v8::internal::MaybeHandle<v8::internal::Name>, char const*, v8::internal::SimpleTransitionFlag) [node]
 8: v8::internal::Map::CopyAddDescriptor(v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [node]
 9: v8::internal::Map::CopyWithField(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Representation, v8::internal::TransitionFlag) [node]
10: v8::internal::Map::TransitionToDataProperty(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Object::StoreFromKeyed) [node]
11: v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::StoreFromKeyed) [node]
12: v8::internal::StoreIC::LookupForWrite(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
13: v8::internal::StoreIC::UpdateCaches(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
14: v8::internal::StoreIC::Store(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
15: v8::internal::Runtime_StoreIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [node]
16: 0x11d8e2e840dd
Done in 146858.94s.
[ec2-user@ip-172-31-35-207 web]$

Hi @acidjazz, I also experienced a memory leak during the last days, but fortunately I was able to track down the error and found out it was my own stupidity. I don't assume that you did any mistake, but maybe my comment here (https://github.com/nuxt/nuxt.js/issues/1728) can encourage you to investigate your problem.

much appreciated @tillkolter reading your post now, did you find this error w/in the backtrace of your memory leak? and how long did production run for before your leak occured?

@acidjazz Do you mean if I found a hint under the Security context section of the GC error message? In that section I found several different stack traces over time. Sometimes I got even
Cannot get stack trace in GC. Unfortunately I also could not find a direct trace for my error in the heapdump. But only by the pure amount of VueComponent objects (and also tons of Watcher objects btw), I could tell that something was wrong and somehow related to an error during rendering. In my case it was pure stupidity and could have saved me if I would have ignored the dev server output which I usually dont. The leak occured between 10 hours and 48 hours, but I thinks it is not a matter of time, but more how much objects were involved around the error and keep clusters of closure references which the garbage collector can not handle. In your case it could be even a malicious watcher (for a Vuex state mutation) if you always get the stacktrace above. My guess is that the overall problem is a co-production between a hand-made (possibly silent) error during the server side rendering process and an actual leak in the framework (either Vue or Nuxt) that keeps closure references after such an error, but I am no senior JS developer and can not prove it yet :)

Another repro, this is now using nuxt.js 1.0.0-rc11:

Done in 34.95s.
yarn start v0.27.5
$ HOST=0.0.0.0 nuxt start

 OPEN  http://localhost:3000


<--- Last few GCs --->

[16915:0x4094f10] 142561826 ms: Mark-sweep 1400.1 (1490.5) -> 1400.1 (1489.5) MB, 2316.1 / 0.0 ms  allocation failure GC in old space requested
[16915:0x4094f10] 142564138 ms: Mark-sweep 1400.1 (1489.5) -> 1400.1 (1489.5) MB, 2310.0 / 0.0 ms  (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 2311 ms) last resort
[16915:0x4094f10] 142566457 ms: Mark-sweep 1400.1 (1489.5) -> 1400.1 (1489.5) MB, 2318.9 / 0.0 ms  last resort


<--- JS stacktrace --->

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

Security context: 0x24058599cca1 <JSObject>
    1: extend(aka extend) [/home/ec2-user/api/web/node_modules/vue-server-renderer/build.js:~178] [pc=0x6a3747c14f1](this=0x240585982241 <undefined>,to=0x3f7926ba57a9 <Object map = 0x1c69f9804829>,_from=0x3f7926bed659 <Object map = 0x11f70bc1bc71>)
    2: renderStyle [/home/ec2-user/api/web/node_modules/vue-server-renderer/build.js:~1976] [pc=0x6a37479644f](this=0x19b2b99f5761 <JSArray[4]>,vnode...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x136916c [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewTransitionArray(int) [node]
 6: v8::internal::TransitionArray::Insert(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Map>, v8::internal::SimpleTransitionFlag) [node]
 7: v8::internal::Map::CopyReplaceDescriptors(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal::Handle<v8::internal::LayoutDescriptor>, v8::internal::TransitionFlag, v8::internal::MaybeHandle<v8::internal::Name>, char const*, v8::internal::SimpleTransitionFlag) [node]
 8: v8::internal::Map::CopyAddDescriptor(v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [node]
 9: v8::internal::Map::CopyWithField(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Representation, v8::internal::TransitionFlag) [node]
10: v8::internal::Map::TransitionToDataProperty(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Object::StoreFromKeyed) [node]
11: v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::StoreFromKeyed) [node]
12: v8::internal::StoreIC::LookupForWrite(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
13: v8::internal::StoreIC::UpdateCaches(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
14: v8::internal::StoreIC::Store(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
15: v8::internal::KeyedStoreIC::Store(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [node]
16: v8::internal::Runtime_KeyedStoreIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [node]
17: 0x6a3737840dd
Done in 142566.92s.
[ec2-user@ip-172-31-35-207 web]$

@acidjazz Did you go through the heap dumping process as recommended in issue 805? Unfortunately your crash report is not providing any useful information.

Here is another dump.

@tillkolter I have not yet, in crunch time right now but as soon as I can find time I will.

yarn start v0.27.5
$ HOST=0.0.0.0 nuxt start

 OPEN  http://localhost:3000


<--- Last few GCs --->

[25292:0x31a4f10] 139828688 ms: Mark-sweep 1399.9 (1495.0) -> 1399.9 (1495.0) MB, 2326.5 / 0.0 ms  allocation failure GC in old space requested
[25292:0x31a4f10] 139831010 ms: Mark-sweep 1399.9 (1495.0) -> 1399.9 (1495.0) MB, 2321.3 / 0.0 ms  last resort
[25292:0x31a4f10] 139833316 ms: Mark-sweep 1399.9 (1495.0) -> 1399.9 (1495.0) MB, 2305.3 / 0.0 ms  last resort


<--- JS stacktrace --->

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

Security context: 0x316fa191cca1 <JSObject>
    1: createWatcher(aka createWatcher) [/home/ec2-user/api/web/node_modules/vue/dist/vue.runtime.common.js:~3310] [pc=0x31ca5262a62a](this=0x316fa1902241 <undefined>,vm=0x351a29232eb1 <Vue$3 map = 0x209f5b45a679>,keyOrFn=0x162175307581 <String[8]: nuxt.err>,handler=0x1621753075a1 <String[12]: errorChanged>,options=0x316fa1902241 <undefined>)
    2: arguments adaptor frame: 3->4
    4: initWatch...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x136916c [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewTransitionArray(int) [node]
 6: v8::internal::TransitionArray::Insert(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Map>, v8::internal::SimpleTransitionFlag) [node]
 7: v8::internal::Map::CopyReplaceDescriptors(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal::Handle<v8::internal::LayoutDescriptor>, v8::internal::TransitionFlag, v8::internal::MaybeHandle<v8::internal::Name>, char const*, v8::internal::SimpleTransitionFlag) [node]
 8: v8::internal::Map::CopyAddDescriptor(v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [node]
 9: v8::internal::Map::CopyWithField(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Representation, v8::internal::TransitionFlag) [node]
10: v8::internal::Map::TransitionToDataProperty(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Object::StoreFromKeyed) [node]
11: v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::StoreFromKeyed) [node]
12: v8::internal::StoreIC::LookupForWrite(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
13: v8::internal::StoreIC::UpdateCaches(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
14: v8::internal::StoreIC::Store(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
15: v8::internal::Runtime_StoreIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [node]
16: 0x31ca51c840dd
Done in 139833.78s.

Another today

yarn start v0.27.5
$ HOST=0.0.0.0 nuxt start

 OPEN  http://localhost:3000


<--- Last few GCs --->

[2013:0x3543f10] 58198471 ms: Mark-sweep 1401.2 (1476.4) -> 1401.2 (1476.4) MB, 2235.7 / 0.0 ms  (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 2236 ms) last resort
[2013:0x3543f10] 58200714 ms: Mark-sweep 1401.2 (1476.4) -> 1401.2 (1476.4) MB, 2243.3 / 0.0 ms  last resort


<--- JS stacktrace --->

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

Security context: 0x2d5ae0c9cca1 <JSObject>
    0: builtin exit frame: assign(this=0x2d5ae0c9b6c9 <JSFunction Object (sfi = 0x2d5ae0c9b619)>,0x1cbc70de0769 <Object map = 0x67fc6b225a1>,0x2e8bcae0cbc1 <Object map = 0x8b0ff218e9>,0x2422aebd8c41 <Object map = 0x67fc6b04829>)

    1: renderAttrs [/home/ec2-user/api/web/node_modules/vue-server-renderer/build.js:~335] [pc=0x19b51c2a7d7f](this=0x777640f5761 <JSArray[4]>,node=0x2422aebd8b31 <VNod...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x136916c [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewTransitionArray(int) [node]
 6: v8::internal::TransitionArray::Insert(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Map>, v8::internal::SimpleTransitionFlag) [node]
 7: v8::internal::Map::CopyReplaceDescriptors(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal::Handle<v8::internal::LayoutDescriptor>, v8::internal::TransitionFlag, v8::internal::MaybeHandle<v8::internal::Name>, char const*, v8::internal::SimpleTransitionFlag) [node]
 8: v8::internal::Map::CopyAddDescriptor(v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [node]
 9: v8::internal::Map::CopyWithField(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Representation, v8::internal::TransitionFlag) [node]
10: v8::internal::Map::TransitionToDataProperty(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Object::StoreFromKeyed) [node]
11: v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::StoreFromKeyed) [node]
12: v8::internal::Object::AddDataProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::ShouldThrow, v8::internal::Object::StoreFromKeyed) [node]
13: v8::internal::Object::SetProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::LanguageMode, v8::internal::Object::StoreFromKeyed) [node]
14: v8::internal::JSReceiver::SetOrCopyDataProperties(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::Handle<v8::internal::Object>, v8::internal::ScopedVector<v8::internal::Handle<v8::internal::Object> > const*, bool) [node]
15: 0xc57957 [node]
16: v8::internal::Builtin_ObjectAssign(int, v8::internal::Object**, v8::internal::Isolate*) [node]
17: 0x19b51c13c8dd
Done in 58201.61s.

I experienced a similar issue, the culprit was @nuxt/[email protected]. I downgraded to the latest 3.x version which is 3.1.4 and the most noticeable memory leak in my Nuxt app stopped.

With @nuxt/[email protected], the axios plugin seems to be registered with every SSR request! 馃槷

screen shot 2017-10-09 at 1 19 57 am

215 Axios instances!
screen shot 2017-10-09 at 1 18 54 am

Since I set --max_old_space_size=400 (512 MB memory small host constraint), the app crashed after only about 200 requests (I was using integrity to crawl the links on the Nuxt app locally).

After downgraded to @nuxtjs/axios@^3.1.4, the symptom went away, and the crawling sustained to more than 1500 pages before I manually stopped. Memory was stable and clocked at around 650 MB when I stopped crawling. There might be other app specific small leakages but this one mentioned was the most obvious and severe.

This is the count for Axios in the heapdump with @nuxtjs/axios@^3.1.4 after I manually stopped the crawler on around 1500 successful SSR page requests:

Only 4 Axios instances
screen shot 2017-10-09 at 1 19 10 am

@onlyurei i think this might be it, i use @nuxtjs/axios everywhere as well and I'm at 4.3, excellent work

I am happy to hear, that memory management seems stable after downgrading Axios, but in my case this should not have been the problem since I use GraphQL with apollo-client instead of axios.

Hi,

I believe it's more related to inject directly, I will investigate with @pi0 on it.

@Atinux any updates in here? My instance on AWS is crashing too.

I am working on it

@Atinux I would like to add that I'm not using axios module, just normal dependency...

@lukasborawski Any other modules/plugins do you use?

@pi0 here are my plugins:

zrzut ekranu 2017-10-17 o 14 10 55

Filters are custom Vue filters.

Thanks for sharing your status. Are you using inject inside your axios plugin?

@pi0 Nope. Just {store, redirect, route}.

Also I've noticed that this might happen after some requests peak.

@pi0 @Atinux guys any updates in here? My client is really mad :)

@pi0 @Atinux ???

@lukasborawski, have you tried running your project with Nuxt's dev branch? It's possible that the issue has been fixed in there, see issue #1984

@paulgv @pi0 @Atinux after switch to develop i've got this:

  nuxt:render Rendering url / +0ms
context.isServer has been deprecated, please use process.server instead.
context.isClient has been deprecated, please use process.client instead.
{ TypeError: Parameter "url" must be a string, not undefined

@lukasborawski the warning is intentional, context.isServer is now deprecated, you have to use process.server now.

About the url parameter, I'm not sure to see where it comes from.

@Atinux but i'm not using isServer at all ;) and i have dozens url params in project :)

The url parameter is caused by (@nuxt/)axios, but I havent found yet why. The stack of the error is

TypeError: Parameter "url" must be a string, not undefined
    at Url.parse (url.js:102:11)
    at Object.urlParse [as parse] (url.js:96:5)
    at dispatchHttpRequest (node_modules/axios/lib/adapters/http.js:58:22)
    at Promise (<anonymous>)
    at httpAdapter (lib/adapters/http.js:18:10)
    at dispatchRequest (lib/core/dispatchRequest.js:51:10)
    at <anonymous>

Just including the @nuxtjs/axios module already causes this error. Again, havent found why yet.

(sorry I pressed comment too soon by mistake)

Again, I'm not using axios module, just axios plugin, but guessing that the problem originally comes from axios it self.

Thats all you need for this error to trigger. I only include @nuxtjs/axios and dont do any request at all and still get this. I also checked the config received by dispatchRequest and that really does contain isServer and isClient. But I dont know yet where that anonymous function comes from...

@pimlie maybe this is an issue for axios team?

No I dont think so, I guess somewhere an object is copied that includes the context which causes the getter methods to be called. And the newly 'assigned' object will just have boolean properties and no getter functions. This could very well be Axios who is doing that, but even then the problem is for Nuxt to fix.

But for me this is only the first hurdle with the current dev branch, as it also doesnt continue rendering pages after these errors. So I guess we will just have to wait a bit longer :smile:

Hello, guys! Not sure, but maybe it will be useful for you.

I had the same problem (TypeError: Parameter "url" must be a string, not undefined) with simple axios plugin:

import axios from 'axios'
export default axios.create({
  baseURL: process.env.apiUrl
})

I misunderstanding docs and include this plugin to the nuxt.config.js:

plugins: ['~plugins/axios']

But to use it correctly I had to include it only to vendors and then import it on pages.

@KonstantinVlasov Why dont you use the 'standard' nuxt axios module? That really has benefits over writing your own plugin ;)
It just doesnt work well currently with the dev branch due to changes because of this memory leak.

I've started project when there were no any nuxt modules, and I'm just fine with it :)

@Atinux Any updates in here?

I have come across the same situation as you, and the project has been online and is always concerned with updates... @lukasborawski

It should be fixed with the next version since I fixed a memory leak, but I am going to add more tests to avoid any regression.

@Atinux know that you guys have lot of work, but what ETA?

When all these tasks will be done: https://trello.com/b/lgy93IOl/nuxtjs-10

Should be at the end of the month

@Atinux Is there any PR that i can use for the time being?

Hey everybody. I had the same problem a while ago. Thought I found the solution and wrote a long post about it. Then it happened again... That was enough!

Six weeks later and the problem didnt cost me another nerve, because I worked around it by putting Nuxt it into a Docker container and started it with restart always. I would love to see this issue solved on the ground level, but I strongly recommend to do what I did and give yourself a little peace meanwhile.

A note on top of @tillkolter 's issue I use pm2 official link , here are some of my package.json scripts:

  "scripts": {
    ...
    "pm2start": "pm2 start yarn.js -- start --name \"web\"",
    "pm2restart": "pm2 restart all",
  },

I have a possible solution. you have to remove @nuxt/axios. The leak comes from this plugin or is triggered from this plugin.

Then create a plugin
plugins/axios.js

import axios from 'axios'
if (process.browser) {
  axios.defaults.baseURL = '/api'
} else {
  axios.defaults.baseURL = 'http://localhost:3000/api'
}

export default axios

Here you check wheater is the browser or the server (SSR) is doing the request.

in the store or pages import this plugin:
import axios from '~/plugins/axios'
DO NOT USE IT IN nuxt.config.js!!

Then do your request and be happy. i.e.:
```javascript
async FETCH_HOMEPAGE_DATA ({ commit }) {
let res = await axios.get('homepage')
commit(types.RECEIVE_HOMEPAGE_DATA, { fetchedHomepageData: res.data.result })
}
````

Tested this in a Kubernetes Cluster (docker) and local (macos) both with node 8.9 When using the nuxt/axios plug the docker restartet when alot of requests came in. (made a curl script that fetches every second.) Now it is stable and is not crashing anymore. i think.

UPDATE:
I also added axios to the vendor in nuxt config
...vendor: ['axios'],...

If anyone else is having issues with Nuxt crashing due to memory leaks or other things and wants a solution that allows your site to be up 100% of the time (restarting after the crash is not a good solution, you will drop clients, and things aren't great when the server is low on ram). Then you're welcome to use a solution I wrote for an application I built in Nuxt.

It will spin up a few workers in a cluster. After a specified amount of time/ amount of requests, the worker will tell the master it's going down soon. At this point, the master will spin up a new worker to replace it (this is important, you don't want to be in a position where there are 0 workers). This has solved all my memory issues, and all my 502 gateway errors (i use nginx in front of it).

It's not packaged or anything, but here is the source:

const cluster = require('cluster');
const os = require('os');
const { Nuxt } = require('nuxt');
const config = require('./nuxt.config.js');
const app = require('express')();
const morgan = require('morgan');

config.dev = false;

const nuxt = new Nuxt(config);

const host = process.env.HOST || '127.0.0.1';
const port = process.env.PORT || 3000;

// default 30 minutes
const MAX_UPTIME = Math.max(process.env.MAX_UPTIME || 0, 5 * 60 * 1000);
const MAX_REQUESTS = Math.max(process.env.MAX_REQUESTS || 0, 100);

const MIN_UPTIME = MAX_UPTIME - (30 * 1000);
const MIN_REQUESTS = MAX_REQUESTS - 50;

const numWorkers = process.env.NUM_WORKERS || os.cpus().length;

function ensureWorkers() {
  for (let i = Object.keys(cluster.workers).length; i < numWorkers; i += 1) {
    cluster.fork();
  }
}

if (cluster.isMaster) {
  ensureWorkers();

  cluster.on('exit', (worker, code, signal) => {
    console.log(
      'worker %d died (%s). restarting...',
      worker.process.pid,
      signal || code,
    );
    ensureWorkers();
  });

  cluster.on('message', (msg) => {
    if (msg === 'BYE') {
      console.log('Spinning up new worker in advance for anticipation of worker shutdown');
      cluster.fork();
    }
  });
} else {
  let numRequests = 0;
  let isClosing = false;
  let server;

  const STOP_AFTER_REQUESTS = Math.round((Math.random() * (MAX_REQUESTS - MIN_REQUESTS)) + MIN_REQUESTS);
  const STOP_AFTER_TIME = Math.round((Math.random() * (MAX_UPTIME - MIN_UPTIME)) + MIN_UPTIME);
  const log = (...args) => {
    console.log(`${process.pid}: `, ...args);
  };

  const close = () => {
    if (isClosing) {
      return;
    }
    isClosing = true;

    process.send('BYE');

    setTimeout(() => {
      log('Shutting down gracefully');
      server.close(() => {
        log('Shutdown complete');
        process.exit(0);
      });
    }, 15000);
  };

  morgan.token('pid', () => process.pid);
  app.use(morgan('[worker: :pid] :status :method :url - :response-time'));

  log('Will shutdown after', STOP_AFTER_REQUESTS, 'requests');
  app.use((req, res, next) => {
    numRequests += 1;
    if (numRequests > STOP_AFTER_REQUESTS) {
      log('Closing due to STOP_AFTER_REQUESTS');
      close();
    }
    log(req.url);
    next();
  });


  log('Will shutdown in', STOP_AFTER_TIME / 1000, 'seconds');
  setTimeout(() => {
    log('Closing due to STOP_AFTER_TIME being reached');
    close();
  }, STOP_AFTER_TIME);

  nuxt.plugin('renderer', (renderer) => {
    renderer.plugin('setupMiddleware', () => {
      log('Up and running');
      app.use(nuxt.render);
      server = app.listen(port, host);
    });
  });
}

I hope it helps.

Hi guys! I can confirm that rc11 don't have memory issues with our project. We have nuxt in production with own simple axios plugin. Also, we had problems with memory leaks with some of our plugin that creates event listeners in created hook, so we move it to mounted hook. Currently, we have 20 requests per seconds on production and no memory problems.

You could also install the next version of nuxt: yarn add nuxt@next. This installs the latest version which should work _most_ of the time. The memory leak has at least been fixed already.
Just test this in your dev setup and if tests are ok use the specific commit hash to install the same version on your production server.

@KonstantinVlasov Have you tried the official axios module? For me there was the mem leak comming from. Can you share your simple axios plugin? Would be interesting. Thank you

@christophwolff I have not tried axios module, because when I start to work with nuxt, there was no modules at all :)
Our plugin really simple:

import axios from 'axios'

let baseURL = process.env.apiUrl

export default axios.create({
  baseURL
})

Important point, you need to and this plugin only to vendors, not plugins.

@KonstantinVlasov Ahh similar to my solution. I think the axios module is causing the Mem Leak. not nuxt.
https://github.com/nuxt/nuxt.js/issues/1695#issuecomment-345444513

Hi there,

Still having huge issues with memory on the latest version (1.0.0-gh-ae754af)
Not even using Axios at all on my side.

<--- Last few GCs --->

[26265:0x102802400] 15703442 ms: Mark-sweep 1376.7 (1597.8) -> 1376.7 (1593.3) MB, 842.0 / 0.0 ms  allocation failure GC in old space requested
[26265:0x102802400] 15704301 ms: Mark-sweep 1376.7 (1593.3) -> 1376.7 (1546.3) MB, 859.0 / 0.0 ms  last resort 
[26265:0x102802400] 15705149 ms: Mark-sweep 1376.7 (1546.3) -> 1376.7 (1533.3) MB, 848.6 / 0.0 ms  last resort 


<--- JS stacktrace --->

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

Security context: 0xf2626d28799 <JSObject>
    1: DoJoin(aka DoJoin) [native array.js:~95] [pc=0x306a4024f30f](this=0x1a622fc82311 <undefined>,p=0x2d2bced95e61 <JSArray[4]>,q=4,E=0x1a622fc823b1 <true>,A=0x1a622fc82471 <String[0]: >,z=0x1a622fc82421 <false>)
    2: Join(aka Join) [native array.js:~120] [pc=0x306a3fb220e9](this=0x1a622fc82311 <undefined>,p=0x2d2bced95e61 <JSArray[4]>,q=4,A=0x1a622fc82471 <String[0]: >,z=0x1a622fc82421 <fals...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/Users/william/.nvm/versions/node/v8.5.0/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/Users/william/.nvm/versions/node/v8.5.0/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/william/.nvm/versions/node/v8.5.0/bin/node]
 4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/Users/william/.nvm/versions/node/v8.5.0/bin/node]
 5: v8::internal::Runtime_StringBuilderConcat(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/william/.nvm/versions/node/v8.5.0/bin/node]
 6: 0x306a3ed846fd
 7: 0x306a4024f30f
 8: 0x306a3fb220e9
 9: 0x306a401561f4
10: 0x306a4024f6c0
11: 0x306a4090b7b9
12: 0x306a3ee79e09
13: 0x306a3ee3f075
14: 0x306a3ed85d7b

And Heroku is getting crazy.

heroku

Waiting for the next stable release of Nuxt to see if it does change something.

@WilliamDASILVA Actually latest release is 1.0.0. Are you getting this error on production mode? (nuxt-start). This problem may be originating from some of used liberaries. Sharing a list of them may help :)

@WilliamDASILVA some plugins or libraries can create event listeners at the created hook, it cause memory leak. In our project we turn off components one by one to find problems code.

@KonstantinVlasov Exactly what i have done. @WilliamDASILVA Trail and error. Sometimes its like that :-/

I get this too but I can't turn off plugins as that would destroy the app

Maybe should add vendor to nuxt.config such as 'vendor: ['axios', 'lodash', 'echarts']'

My issue I think was a custom error page which never was reached. It would try to render everything after / that wasn't a page as a custom page for some reason.

Fixing error layout made it work again but this might be another issue

In my observation with nuxt 1.1.1 and nuxtjs/axios, the memory leak situation is eased a lot. Now my app occupied 630m after 8601 reqs. The same code under nuxt 1.0.0-rc11 will quickly occupy 1.6G and then OOM after 1921 reqs.

The memory usage is still increasing along with incoming requests, but very slow. I guess axios module is no longer a main cause of memory leak.

Yes I can confirm the memory leaks are gone with 1.1.1 so far

I have a site with nuxt:1.2.1 and nuxtjs/axios:4.5.2 that has been live for 5 days with no problems. I upgraded to nuxtjs/axios:5.0.0-rc.2 yesterday and immediately saw a memory problem.

Just FYI.

memory-leak

@psnoonan Would you please open an issue in axios-module repo with more details (Memory dump or Nuxt config). BTW thanks for the report.

@psnoonan What do you use for memory tracking and for the charts?

@pi0 @Atinux what is the preferred version of Axios that is not crashing the app for sure? I'm also still experiencing the memory leaks. I'm not using the Axios module. Just clean installation.

zrzut ekranu 2018-02-02 o 15 24 48

Unfortunately, this is not only axios causing leaks. Although, axios module has some internal workarounds to prevent known issues. So using it is recommended. We try to continuously check for new problems.

@awronski It is heroku, I think.

@awronski Yes, it is Heroku

@pi0 Indeed, axios is not the only thing causing leaks. I also had one listener in the created() lifecycle event, in one component only, and it was enough to cause a slow rise in memory usage. I switched to mounted() and it seems to have gone away.

I did some more testing today and started adding in the things that seemed to be causing the memory issues, one by one and letting them sit for a few hours.

I updated the nuxtjs/axios module version to 5.0.0-rc2, and there were no issues.
Then I added the timeout code back, and there were no issues.

I guess the memory problem was only from the listener in the created lifecycle event, and not from nuxtjs/axios.

Sorry!

@psnoonan what is the solution then?

@lukasborawski I put my listener in a mounted hook instead of a created hook.

@leahciMic This doesn't work for me. Gives a lot of errors loading other components and breaks the site. Also receiving 502 error when navigating to other pages besides homepage
image

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VincentLoy picture VincentLoy  路  3Comments

bimohxh picture bimohxh  路  3Comments

gary149 picture gary149  路  3Comments

vadimsg picture vadimsg  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments