Lift-off-part5/deploying-apollo-client: heroku app crashing due to JavaScript heap out of memory

Once the client application was deployed to heroku servers. It would build and render successfully. However after about 30 seconds it would crash due to a JavaScript heap out of memory error.

heroku logs will look like this:

: webpack compiled successfully
[web.1]: <--- Last few GCs --->
[web.1]: [29:0x6a058c0]    47970 ms: Mark-sweep (reduce) 243.2 (257.6) -> 243.2 (257.1) MB, 875.1 / 0.1 ms  (average mu = 0.121, current mu = 0.000) allocation failure GC in old space requested
[web.1]: [29:0x6a058c0]    48809 ms: Mark-sweep (reduce) 243.2 (257.1) -> 243.2 (257.1) MB, 839.1 / 0.1 ms  (average mu = 0.056, current mu = 0.000) last resort GC in old space requested
[web.1]: <--- JS stacktrace --->
[web.1]: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
[web.1]: 1: 0xb02930 node::Abort() [/app/.heroku/node/bin/node]
2022-08-19T08:46:32.175468+00:00 app[web.1]: 2: 0xa18149 node::FatalError(char const*, char const*) [/app/.heroku/node/bin/node]
[web.1]: 3: 0xcdd16e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/app/.heroku/node/bin/node]
[web.1]: 4: 0xcdd4e7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/app/.heroku/node/bin/node]
[web.1]: 5: 0xe94b55  [/app/.heroku/node/bin/node]
[web.1]: 6: 0xe95636  [/app/.heroku/node/bin/node]
[web.1]: 7: 0xea3b5e  [/app/.heroku/node/bin/node]
[web.1]: 8: 0xea45a0 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/app/.heroku/node/bin/node]
[web.1]: 9: 0xea6776 v8::internal::Heap::CollectAllAvailableGarbage(v8::internal::GarbageCollectionReason) [/app/.heroku/node/bin/node]
[web.1]: 10: 0xea7582 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/app/.heroku/node/bin/node]
[web.1]: 11: 0xe68792 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [/app/.heroku/node/bin/node]
[web.1]: 12: 0xe630ac v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawArray(int, v8::internal::AllocationType) [/app/.heroku/node/bin/node]
[web.1]: 13: 0xe63185 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller(v8::internal::Handle<v8::internal::Map>, int, v8::internal::Handle<v8::internal::Oddball>, v8::internal::AllocationType) [/app/.heroku/node/bin/node]
[web.1]: 14: 0x10cba0e v8::internal::MaybeHandle<v8::internal::OrderedHashMap> v8::internal::OrderedHashTable<v8::internal::OrderedHashMap, 2>::Allocate<v8::internal::Isolate>(v8::internal::Isolate*, int, v8::internal::AllocationType) [/app/.heroku/node/bin/node]
[web.1]: 15: 0x10cbac3 v8::internal::MaybeHandle<v8::internal::OrderedHashMap> v8::internal::OrderedHashTable<v8::internal::OrderedHashMap, 2>::Rehash<v8::internal::Isolate>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::OrderedHashMap>, int) [/app/.heroku/node/bin/node]
[web.1]: 16: 0x11d7bf5 v8::internal::Runtime_MapGrow(int, unsigned long*, v8::internal::Isolate*) [/app/.heroku/node/bin/node]
[web.1]: 17: 0x15d5439  [/app/.heroku/node/bin/node]
[web.1]: Process exited with status 1
[web.1]: State changed from up to crashed

To resolve this, I added within the client project heroku dashboard → Settings → Config Vars a single key which increases memory allowance:

Value: --max_old_space_size=1024

After adding this and previewing the application in the browser, heroku rebuilt the application and it has not crashed since.

Was this the correct step to take to resolve this issue or is there a memory leak that should be fixed?

Hi @Eldroy, thanks for the info! I haven’t come across this error before. We can keep an eye to see if it pops up again, I’m glad you were able to find a workaround.

To confirm, was this from the first time you deployed the app, following the steps in this lesson? Deploying Apollo Client | Lift-off V: Production & the Schema Registry | Apollo Odyssey

Is your server deploy working smoothly?

Hi @MichelleMabuyo,

Yes that is correct, it was from the first time deploying the app following the steps in the Deploying Apollo Client lesson.

Yes the server deploy is working smoothly. I have opened the heroku application again today and it still is running and has not crashed.

I also encountered this error. Upon comparing the final and my main branch, I saw that the react-scripts library has different versions. So what I did was downgrade the react-scripts to 4.0.3, which is the version used in the final. It works for me.

1 Like

(post deleted by author)

Thanks, it works for me

1 Like