jsonapi-serializer icon indicating copy to clipboard operation
jsonapi-serializer copied to clipboard

JavaScript heap out of memory

Open jboler opened this issue 6 years ago • 4 comments

v3.5.7 and all later versions crash. v3.5.6 works fine.

Here's my failing example code:

package.json

{
  "name": "blah",
  "version": "0.0.8",
  "dependencies": {
    "jsonapi-serializer": "3.6.4"
  }
}

main.js

const jsonapi = require('jsonapi-serializer');
const JSONAPIDeserializer = jsonapi.Deserializer;
const JSONAPISerializer = jsonapi.Serializer;

const AppSerializer = new JSONAPISerializer('applications', {
  attributes: ['name']
});

const AppRoleSerializer = new JSONAPISerializer('app_roles', {
  attributes: ['name', 'application'],
  application: {
    ref: 'id',
  },
});

function deserialize(data) {
  return new JSONAPIDeserializer({ keyForAttribute: 'underscore_case' }).deserialize(data);
}

const payload = {
  data: [
    {
      id: '11409008',
      type: 'applications',
      attributes: {
        name: 'blah'
      },
      relationships: {
        app_roles: {
          links: {
            related: 'https://www.myappname.com/api/v2/applications/11409008/app_roles'
          },
          data: [
            {
              type: 'app_roles',
              id: '272824908'
            }
          ]
        }
      },
      links: {
        self: 'https://www.myappname.com/api/v2/applications/11409008'
      }
    }
  ],
  included: [
    {
      id: '272824908',
      type: 'app_roles',
      attributes: {
        name: 'AAA',
        description:null
      },
      relationships: {
        includes: {
          links: {
            related: 'https://www.myappname.com/api/v2/app_roles/272824908/includes'
          }
        },
        application: {
          meta: {
            included:false
          }
        }
      },
      links: {
        self: 'https://www.myappname.com/api/v2/app_roles/272824908'
      }
    },
  ],
  links: {
    self: 'https://www.myappname.com/api/v2/applications?include=app_roles&filter[name]=blah'
  },
  meta: { },
  jsonapi: {
    version: '1.0'
  }
};

deserialize(payload).then(res => console.dir(res, { depth: null }));
<--- Last few GCs --->

[29752:0x25c8710]    24661 ms: Mark-sweep 1281.8 (1304.8) -> 1281.8 (1304.8) MB, 3394.7 / 0.0 ms  allocation failure GC in old space requested
[29752:0x25c8710]    28056 ms: Mark-sweep 1281.8 (1304.8) -> 1281.8 (1297.8) MB, 3394.8 / 0.0 ms  last resort GC in old space requested
[29752:0x25c8710]    31398 ms: Mark-sweep 1281.8 (1297.8) -> 1281.8 (1297.8) MB, 3342.2 / 0.0 ms  last resort GC in old space requested


<--- JS stacktrace --->

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

Security context: 0xe7c42925879 <JSObject>
    1: baseTimes [/home/.../.../node_modules/lodash/_baseTimes.js:~10] [pc=0xeef4f2856fa](this=0xd241928c2f1 <JSGlobal Object>,n=272824909,iteratee=0xe7c429160f9 <JSFunction String (sfi = 0x1ca8e6ea6911)>)
    2: arrayLikeKeys [/home/.../.../node_modules/lodash/_arrayLikeKeys.js:28] [bytecode=0x3ad1e1485d19 offset=102](this=0xd241928c2f1 <JS...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x8cbf4c [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [node]
 6: v8::internal::HashTable<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::NewInternal(v8::internal::Isolate*, int, v8::internal::PretenureFlag) [node]
 7: v8::internal::HashTable<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::New(v8::internal::Isolate*, int, v8::internal::PretenureFlag, v8::internal::MinimumCapacity) [node]
 8: v8::internal::HashTable<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::EnsureCapacity(v8::internal::Handle<v8::internal::SeededNumberDictionary>, int, v8::internal::PretenureFlag) [node]
 9: v8::internal::Dictionary<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::Add(v8::internal::Handle<v8::internal::SeededNumberDictionary>, unsigned int, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyDetails, int*) [node]
10: 0xd7c436 [node]
11: 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) [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::Runtime::SetObjectProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::LanguageMode) [node]
15: v8::internal::Runtime_KeyedStoreIC_Slow(int, v8::internal::Object**, v8::internal::Isolate*) [node]
16: 0xeef4f1042fd
Aborted (core dumped)

jboler avatar Nov 28 '18 20:11 jboler

Maybe related to https://github.com/SeyZ/jsonapi-serializer/pull/193 ?

he9qi avatar Jan 13 '19 20:01 he9qi

I'm having this exact same issue. Anyone know what's going on?

grangerjs avatar Feb 07 '19 22:02 grangerjs

Yep, definitely #193 -- bug with deserializing numeric IDs

davidgovea avatar Aug 22 '19 00:08 davidgovea

@SeyZ are you around? Could we have this fixed?

saulotoledo avatar Jun 01 '20 22:06 saulotoledo