Skip to content

Memory Leak when using top-level await before defining computed translations #2629

Closed
@azhirov

Description

@azhirov

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:

  1. Clone the repository: git clone [email protected]:azhirov/nuxt-i18n-pinia-memory-leak.git
  2. Install dependencies: npm install
  3. Build the project: npm run build
  4. Run the server: node .output/server/index.mjs
  5. 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 or ab -n 5000 -c 100 http://localhost:3000/
  6. 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.

node_1091683

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).

node_1093319

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    v8workaround❗ p4-importantPriority 4: bugs that violate documented behavior, or significantly impact perf

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions