Node crashes periodically

Latest log, happens a lot. support tells me to upgrade the plan, which I did. and still happen :frowning:

9:34:45 PM <— Last few GCs —>
Jan 6 09:34:45 PM
Jan 6 09:34:45 PM [47:0x62b4900] 7463203 ms: Mark-sweep (reduce) 1532.8 (1539.6) -> 1530.7 (1543.1) MB, 4165.2 / 0.0 ms (+ 0.2 ms in 321 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 4304 ms) (average mu = 0.166, current mu = 0.074) a[47:0x62b4900] 7467506 ms: Mark-sweep (reduce) 1531.9 (1541.3) -> 1531.8 (1542.1) MB, 4301.5 / 0.0 ms (average mu = 0.083, current mu = 0.000) allocation failure scavenge might not succeed
Jan 6 09:34:45 PM
Jan 6 09:34:45 PM
Jan 6 09:34:45 PM <— JS stacktrace —>
Jan 6 09:34:45 PM
Jan 6 09:34:45 PM FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Jan 6 09:34:45 PM 1: 0xa03530 node::Abort() [node]
Jan 6 09:34:45 PM 2: 0x94e471 node::FatalError(char const*, char const*) [node]
Jan 6 09:34:45 PM 3: 0xb7773e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
Jan 6 09:34:45 PM 4: 0xb77ab7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
Jan 6 09:34:45 PM 5: 0xd32345 [node]
Jan 6 09:34:45 PM 6: 0xd32ecf [node]
Jan 6 09:34:45 PM 7: 0xd40f5b v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
Jan 6 09:34:45 PM 8: 0xd44b1c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
Jan 6 09:34:45 PM 9: 0xd131fb v8::internal::factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
Jan 6 09:34:45 PM 10: 0x10592f0 v8::internal::Runtime_AllocateInOldGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
Jan 6 09:34:45 PM 11: 0x13ff179 [node]
Jan 6 09:34:45 PM Aborted
Jan 6 09:34:45 PM npm ERR! code ELIFECYCLE

I did some googling around for the error message and it looks like you might need to set:
--max-old-space-size to a higher value.

I found these links to be helpful:

Thanks!

Where would you set this up? on every build?

My understanding is that you can set the flag as part of your startCommand on Render.

Example: startCommand: "node --max-old-space-size=102400 ./app.js"

Another option is to set the NODE_OPTIONS env var. Eg:

NODE_OPTIONS="--max-old-space-size=8192"