question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nuxt 3: SSR memory leak in `useHead()` with computed getter on the server

See original GitHub issue

Environment

  • Operating System: Linux
  • Node Version: v16.15.0
  • Nuxt Version: 3.0.0-rc.11
  • Nitro Version: 0.5.4
  • Package Manager: npm@8.5.5
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

<script setup lang="ts">
import { useHead } from '#head';

// ...

useHead(() => getMeta(meta.value));
</script>

Describe the bug

Using a computed getter (() => ...)) as an argument of the getHead() results to memory leak on the server.

See also: https://github.com/nuxt/framework/issues/8003.

Temporary fix

<script setup lang="ts">
import { useHead } from '#head';

// ...

if (process.server) {
  useHead(getMeta(meta.value));
} else {
  useHead(() => getMeta(meta.value));
}
</script>

Additional context

Memory consumption

Production build of an application, 60 requests per second, 10 minutes of load (36 000 requests).

Before fix

image

After fix

image

Memory difference

Flame graph

image

Table

image

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
danielroecommented, Oct 25, 2022

The issue here was not actually (IIRC) the use of useHead within the component but rather that Nuxt itself was calling use head in a plugin meaning that computed was being called outside of component setup.

I believe this is resolved as computed is no longer being called by @vueuse/head, and functional/computed types are excluded from app.head in nuxt.config.

Let me know if not and I’ll happily reopen.

2reactions
mrauhucommented, Oct 9, 2022

I have a question off topic. What is the name of the program/application you use to track of memory?

@antlionguard Datadog APM with Continuous profiler.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solving server-side memory leaks on Nuxt.js - Medium
In this article, you'll find our historic with server-side memory leaks on Nuxt.js, as well as the process we established to detect them...
Read more >
Nuxt huge memory usage / leakage and how to prevent
It will cause memory leak on server-side. So using Vue.use() inside injection function may cause memory leakage not Vue.use() itself.
Read more >
Functions | VueUse
useEventSource-an EventSource or Server-Sent-Events instance opens a persistent connection to ... resolveRef-normalize value/ref/getter to ref or computed.
Read more >
Scaling Nuxt : r/Nuxt - Reddit
Do you guys encounter any performance bottlenecks with server-side rendering in Nuxt? I'm working on a what I would consider a medium scale ......
Read more >
Nuxt Collate 030421 | PDF | Namespace - Scribd
You do not need to add ssr: true to your nuxt config in order to enable server-side-rendering as it is enabled by default....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found