Description
Environment
- Operating System: Linux
- Node Version: v20.8.1
- Nuxt Version: 3.8.2
- CLI Version: 3.10.0
- Nitro Version: 2.8.1
- Package Manager: [email protected]
- Builder: -
- User Config: app, modules, devtools
- Runtime Modules: @pinia/[email protected], @nuxtjs/[email protected]
- Build Modules: -
Reproduction
I've created a minimal reproduction repository to illustrate the problem. To reproduce the issue:
- Clone the repository:
git clone [email protected]:azhirov/nuxt-i18n-pinia-memory-leak.git
- Install dependencies:
npm install
- Build the project:
npm run build
- Run the server:
node .output/server/index.mjs
- Use a tool like
ab
,siege
, or any other utility to send multiple requests. For example:siege -c10 -t30s http://127.0.0.1:3000
orab -n 5000 -c 100 http://localhost:3000/
- Check the memory consumption of the process (for example, using the
top
command).
Describe the bug
I've encountered a peculiar memory leak issue related to the simultaneous usage of the @nuxtjs/i18n
and @pinia/nuxt
modules in a Nuxt 3 project. The problem manifests when an asynchronous method from the Pinia store is called (using await
) before a computed
property that includes useNuxtApp().$i18n.t()
. This results in a memory leak. Interestingly, moving the asynchronous method below the computed
property prevents the leak. Additionally, if the $i18n.t()
is not used in the computed property, the leak does not occur.
Code with memory leak:
import useFooStore from '~/store/foo';
const fooStore = useFooStore();
await fooStore.loadData()
const text = computed(() => {
const i18n = useNuxtApp().$i18n;
return i18n.t('seventeen');
})
After running the command node .output/server/index.mjs
, the server consumes approximately 20 MB of RAM. However, after executing the command siege -c10 -t30s http://127.0.0.1:3000
, the memory usage increases to 1.4 GB and remains at approximately this level even after stopping the load.
If you move the await
call to the asynchronous method of the store below the computed property, the graph looks like this (the memory leak is significantly reduced, and memory consumption resets to almost the initial level).
I've noticed an interesting pattern: the memory leak seems to intensify with an increase in the number of translation files (in the lang
directory).
Additional context
A similar issue was mentioned earlier in this comment: #2034 (comment). After updating to version 8.0.0-rc.11
, the problem reproduces only when using Pinia. A simple asynchronous function defined within the same component does not trigger the memory leak.
Logs
No response
Activity