ardatan/graphql-toolkit

epoxy out of memory when merging directives

Closed this issue ยท 7 comments

alx13 commented

I'm trying to use directives in GraphQLModules, but when I'm typing directive like:

directive @access(via: [String] = "id") on FIELD_DEFINITION

type User {
  id: ID!
  field: String! @access(via: ["id"])
}

I'm getting OOM

<--- Last few GCs --->
 i[57954:0x102640000]    16290 ms: Mark-sweep 3583.9 (3632.9) -> 1738.4 (1793.4) MB, 102.8 / 0.1 ms  (+ 41.1 ms in 10 steps since start of marking, biggest step 30.8 ms, walltime since start of marking 4517 ms) (average mu = 0.983, current mu = 0.983) alloc[57954:0x102640000]    21262 ms: Mark-sweep 3458.6 (3513.9) -> 1284.1 (1347.1) MB, 676.3 / 0.0 ms  (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 1933 ms) (average mu = 0.924, current mu = 0.864) allocati

<--- JS stacktrace --->

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

    0: ExitFrame [pc: 0x27cac225be3d]
Security context: 0x2c449f71e6e1 <JSObject>
    1: mergeArguments(aka mergeArguments) [0x2c447b8b9999] [/Users/alx13/apps/node_modules/.registry.npmjs.org/graphql-toolkit/0.2.9/node_modules/graphql-toolkit/dist/commonjs/epoxy/typedefs-mergers/directives.js:~10] [pc=0x27cac252a3d4](this=0x2c44957826f1 <undefined>,a1=0x2c4495575c61 <JSArray[1]>,a2=0x2c4495575c61 <...

FATAL ERROR: invalid array length Allocation failed - JavaScript heap out of memory
 1: 0x10003b1db node::Abort() [/Users/alx13/.nvm/versions/node/v10.15.1/bin/node]
 2: 0x10003b3e5 node::OnFatalError(char const*, char const*) [/Users/alx13/.nvm/versions/node/v10.15.1/bin/node]
 3: 0x1001a86b5 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/alx13/.nvm/versions/node/v10.15.1/bin/node]
 4: 0x100573ad2 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/Users/alx13/.nvm/versions/node/v10.15.1/bin/node]
 5: 0x10054c2aa v8::internal::Factory::NewFixedArrayWithFiller(v8::internal::Heap::RootListIndex, int, v8::internal::Object*, v8::internal::PretenureFlag) [/Users/alx13/.nvm/versions/node/v10.15.1/bin/node]
 6: 0x1004f36fe v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::GrowCapacity(v8::internal::Handle<v8::internal::JSObject>, unsigned int) [/Users/alx13/.nvm/versions/node/v10.15.1/bin/node]
 7: 0x10078e83f v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/alx13/.nvm/versions/node/v10.15.1/bin/node]
 8: 0x27cac225be3d

If I'm not using array in directive definition, everything works fine:

directive @access(via: String = "id") on FIELD_DEFINITION

type User {
  id: ID!
  field: String! @access(via: "id")
}

It's stacking really fast in here: https://github.com/ardatan/graphql-toolkit/blob/master/src/epoxy/typedefs-mergers/directives.ts#L24
when GraphQLModules dependencies tree is large.
Maybe we should not concatenate array arguments for directives?

#119 should fix it

@alx13 do you have or could create a small reproduction? Something I could test myself if it's solved

alx13 commented

Working, thanks!

Released as 1.3.0