'What is the reason only specific Heroku deployment crashing out of memory?
I have the same code on staging and production deployments on Heroku (totally free plan for both).
Unfortunately, as I've realized recently, the staging deployment crashes very regularly as I suspect there might be a memory leak somewhere in the app, or a garbage collection problem for some reason.
But what I definitely don't understand is that it only happens on staging, and not on production, meanwhile they have the same exact code running.
The synopsis of difference between the two environments is that staging runs directly on Heroku meanwhile production is accessed from a Cloudflare integrated domain.
The application is MERN stack with Next.js and both environments use HTTPS.
Here is the log dump from the point when it happens:
2022-02-17T14:57:10.368421+00:00 heroku[router]: at=info method=GET path="/_next/webpack-hmr" host=some-host-hehe.herokuapp.com request_id=79d9d976-583d-4f20-a4dc-fe68defc6d68 fwd="some-ip-hehe" dyno=web.1 connect=0ms service=3946ms status=101 bytes=398 protocol=https
2022-02-17T14:57:11.094439+00:00 heroku[router]: at=info method=GET path="/_next/static/chunks/pages/_app.js?ts=1645109830161" host=some-host-hehe.herokuapp.com request_id=9f060376-ba2f-485e-9e74-6b6704ac9455 fwd="some-ip-hehe" dyno=web.1 connect=0ms service=600ms status=200 bytes=1663193 protocol=https
2022-02-17T14:57:09.569111+00:00 heroku[router]: at=info method=GET path="/_next/static/webpack/1c8154bcc49aab1b.webpack.hot-update.json" host=some-host-hehe.herokuapp.com request_id=17e35593-844c-40d5-a01b-6127761ec8c9 fwd="some-ip-hehe" dyno=web.1 connect=0ms service=1021ms status=404 bytes=3435 protocol=https
2022-02-17T14:57:10.414725+00:00 heroku[router]: at=info method=GET path="/_next/static/chunks/webpack.js?ts=1645109830161" host=some-host-hehe.herokuapp.com request_id=db2b7311-78de-48a0-89a7-a4fcacbd8277 fwd="some-ip-hehe" dyno=web.1 connect=0ms service=17ms status=200 bytes=10052 protocol=https
2022-02-17T14:57:10.903246+00:00 heroku[router]: at=info method=GET path="/_next/static/chunks/main.js?ts=1645109830161" host=some-host-hehe.herokuapp.com request_id=66ebce74-77f1-41ac-99f4-a226e46a3e76 fwd="some-ip-hehe" dyno=web.1 connect=0ms service=506ms status=200 bytes=985520 protocol=https
2022-02-17T14:57:12.141179+00:00 heroku[router]: at=info method=GET path="/icons/fav-light.ico" host=some-host-hehe.herokuapp.com request_id=230ec75e-279c-4ec1-8d5d-20c7e94a3393 fwd="some-ip-hehe" dyno=web.1 connect=0ms service=34ms status=304 bytes=238 protocol=https
2022-02-17T14:57:10.769822+00:00 heroku[router]: at=info method=GET path="/_next/static/development/_buildManifest.js?ts=1645109830161" host=some-host-hehe.herokuapp.com request_id=0c340da7-9577-4488-8607-322013a69e4b fwd="some-ip-hehe" dyno=web.1 connect=1ms service=58ms status=200 bytes=693 protocol=https
2022-02-17T14:57:10.479271+00:00 heroku[router]: at=info method=GET path="/_next/static/chunks/react-refresh.js?ts=1645109830161" host=some-host-hehe.herokuapp.com request_id=80b9e79b-40d9-4ddb-8de0-117918cd454d fwd="some-ip-hehe" dyno=web.1 connect=1ms service=14ms status=200 bytes=24964 protocol=https
2022-02-17T14:57:10.660875+00:00 heroku[router]: at=info method=GET path="/_next/static/chunks/pages/index.js?ts=1645109830161" host=some-host-hehe.herokuapp.com request_id=e7df7803-7483-4faf-be37-4bdef838fe0d fwd="some-ip-hehe" dyno=web.1 connect=0ms service=84ms status=200 bytes=24684 protocol=https
2022-02-17T14:58:11.364543+00:00 heroku[router]: at=info method=GET path="/_next/webpack-hmr" host=some-host-hehe.herokuapp.com request_id=42711fcd-bec7-4701-87a8-370e66907267 fwd="some-ip-hehe" dyno=web.1 connect=0ms service=59877ms status=101 bytes=129 protocol=https
2022-02-17T14:58:11.566796+00:00 heroku[web.1]: Process exited with status 134
2022-02-17T14:58:11.302704+00:00 app[web.1]:
2022-02-17T14:58:11.302712+00:00 app[web.1]: <--- Last few GCs --->
2022-02-17T14:58:11.302712+00:00 app[web.1]:
2022-02-17T14:58:11.302720+00:00 app[web.1]: [22:0x622a730] 95427 ms: Mark-sweep (reduce) 251.1 (258.4) -> 250.2 (258.8) MB, 310.9 / 0.0 ms (average mu = 0.615, current mu = 0.178) allocation failure scavenge might not succeed
2022-02-17T14:58:11.302720+00:00 app[web.1]: [22:0x622a730] 95747 ms: Mark-sweep (reduce) 251.2 (258.8) -> 250.9 (259.5) MB, 307.2 / 0.0 ms (average mu = 0.451, current mu = 0.040) allocation failure GC in old space requested
2022-02-17T14:58:11.302720+00:00 app[web.1]:
2022-02-17T14:58:11.302720+00:00 app[web.1]:
2022-02-17T14:58:11.302721+00:00 app[web.1]: <--- JS stacktrace --->
2022-02-17T14:58:11.302721+00:00 app[web.1]:
2022-02-17T14:58:11.302725+00:00 app[web.1]: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
2022-02-17T14:58:11.304079+00:00 app[web.1]: 1: 0xb09980 node::Abort() [node]
2022-02-17T14:58:11.304107+00:00 app[web.1]: 2: 0xa1c235 node::FatalError(char const*, char const*) [node]
2022-02-17T14:58:11.304643+00:00 app[web.1]: 3: 0xcf77be v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
2022-02-17T14:58:11.305207+00:00 app[web.1]: 4: 0xcf7b37 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
2022-02-17T14:58:11.305908+00:00 app[web.1]: 5: 0xeaf3d5 [node]
2022-02-17T14:58:11.306652+00:00 app[web.1]: 6: 0xebf09d v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
2022-02-17T14:58:11.307374+00:00 app[web.1]: 7: 0xec1d9e v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
2022-02-17T14:58:11.308052+00:00 app[web.1]: 8: 0xe83012 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [node]
2022-02-17T14:58:11.308858+00:00 app[web.1]: 9: 0xe7b624 v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawWithImmortalMap(int, v8::internal::AllocationType, v8::internal::Map, v8::internal::AllocationAlignment) [node]
2022-02-17T14:58:11.309559+00:00 app[web.1]: 10: 0xe7c791 v8::internal::FactoryBase<v8::internal::Factory>::NewByteArray(int, v8::internal::AllocationType) [node]
2022-02-17T14:58:11.310135+00:00 app[web.1]: 11: 0xdfabb3 v8::internal::TranslationArrayBuilder::ToTranslationArray(v8::internal::Factory*) [node]
2022-02-17T14:58:11.310861+00:00 app[web.1]: 12: 0x1c28456 v8::internal::compiler::CodeGenerator::GenerateDeoptimizationData() [node]
2022-02-17T14:58:11.311576+00:00 app[web.1]: 13: 0x1c28b65 v8::internal::compiler::CodeGenerator::FinalizeCode() [node]
2022-02-17T14:58:11.312255+00:00 app[web.1]: 14: 0x1cb3191 v8::internal::compiler::PipelineImpl::FinalizeCode(bool) [node]
2022-02-17T14:58:11.312896+00:00 app[web.1]: 15: 0x1cb4193 v8::internal::compiler::PipelineCompilationJob::FinalizeJobImpl(v8::internal::Isolate*) [node]
2022-02-17T14:58:11.313446+00:00 app[web.1]: 16: 0xd8f0f0 v8::internal::OptimizedCompilationJob::FinalizeJob(v8::internal::Isolate*) [node]
2022-02-17T14:58:11.314178+00:00 app[web.1]: 17: 0xd93cab v8::internal::Compiler::FinalizeOptimizedCompilationJob(v8::internal::OptimizedCompilationJob*, v8::internal::Isolate*) [node]
2022-02-17T14:58:11.314814+00:00 app[web.1]: 18: 0xdb61c3 v8::internal::OptimizingCompileDispatcher::InstallOptimizedFunctions() [node]
2022-02-17T14:58:11.315387+00:00 app[web.1]: 19: 0xe4f227 v8::internal::StackGuard::HandleInterrupts() [node]
2022-02-17T14:58:11.316309+00:00 app[web.1]: 20: 0x11fb8f4 v8::internal::Runtime_StackGuardWithGap(int, unsigned long*, v8::internal::Isolate*) [node]
2022-02-17T14:58:11.317287+00:00 app[web.1]: 21: 0x15f0a99 [node]
2022-02-17T14:58:11.365858+00:00 app[web.1]: Aborted
2022-02-17T14:58:11.687487+00:00 heroku[web.1]: State changed from up to crashed
2022-02-17T14:58:20.435690+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/_next/webpack-hmr" host=some-host-hehe.herokuapp.com request_id=80399858-febc-4137-a407-33a1f1c83346 fwd="some-ip-hehe" dyno= connect= service= status=503 bytes= protocol=https
2022-02-17T14:58:26.415083+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/_next/webpack-hmr" host=some-host-hehe.herokuapp.com request_id=1446688b-8458-42c6-94ab-cc516637f9fd fwd="some-ip-hehe" dyno= connect= service= status=503 bytes= protocol=https
2022-02-17T14:58:32.414124+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/_next/webpack-hmr" host=some-host-hehe.herokuapp.com request_id=cfb3076b-30a2-4fb8-a648-ed44b0ce7e2b fwd="some-ip-hehe" dyno= connect= service= status=503 bytes= protocol=https
2022-02-17T14:58:38.404277+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/_next/webpack-hmr" host=some-host-hehe.herokuapp.com request_id=aa46a8a8-0e5d-4770-8b1c-a127223aa2f8 fwd="some-ip-hehe" dyno= connect= service= status=503 bytes= protocol=https
tldr: I want to understand why this could happen with the same exact code deployed on two different environments.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
