unhead: Memory Leak
Environment
- Operating System:
Linux
- Node Version:
v20.5.1
- Nuxt Version:
3.8.2
- CLI Version:
3.10.0
- Nitro Version:
2.8.0
- Package Manager:
npm@9.8.0
- Builder:
-
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Reproduction
When i crawled our web, crashes by memory leak
Describe the bug
When i crawled our web, crashes by memory leak
Additional context
No response
Logs
No response
About this issue
- Original URL
- State: open
- Created 7 months ago
- Comments: 16 (3 by maintainers)
I investigated too 😭 😂 I have one or two other theories on suspect code, maybe we can have a look together in the coming days @harlan-zw or @BobbieGoede? If you have time next week, we could meet on Discord to stop the leak 🧹
BTW, while I was searching for what could be leaking memory in the i18n module I often saw this pattern (
Symbol(__DEV__ ? 'LIB_KEY_HERE' : '')
which obscures/removes the identifying global key in a production build.I guess the primary reason for doing this is to reduce the build size, but a side effect is that we don’t see these keys when debugging memory (which I have only done on a production build). Since unhead does not use this pattern, and it uses some memory, it will be one of the first things you’ll see when debugging which doesn’t necessarily mean that it is leaking.
I can explain better than the opener of the bug. He is right. I was wasted a day to debug a similar bug in my code, so I can explain better.
The leak is in the
$vm._
of vue, persisted in node memory by the global__unhead_injection_handler__
and its friends, so after the SSR page go down, the memory is not freed and stayed in memory again and again.I did some testing with clinic.js and was not able to replicate any sort of memory leak.
This is with ~500 connections doing ~5k requests x2 on a Nuxt app.
Will leave this issue open in case anyone has any further research they can share. (I tried testing with other clinic.js tools but it was failing).
Looks like a vue-router stack? $head is a singleton on the vue VM (like globalProperties), so not sure what you’re showing here exactly.
Not to say there isn’t an issue, but this doesn’t help me identify anything from Unhead’s side.
Also, see comment above.
This is something I do want to take a deeper look into in any case but I’m currently limited with time so unless more people are reporting memory leak issues with Nuxt / Unhead then it’s a low priority as it’s going to be a lengthy investigation.
Thank you for your investigation @BobbieGoede! Some great work on @nuxtjs/i18n 👏