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.

Memory leak in `destr` package, Nuxt 3 production usage

See original GitHub issue

Hello, @pi0.

I found a memory leak, that affects Nuxt 3 framework, because the destr package is used as default parseResponse option in the ohmyfetch, that used in the Nuxt 3 useFetch() function as $fetch.

Memory leak

Flamegraph

image

Table

image

Memory usage

image

Temporary fix for Nuxt 3

  1. Create a local TypeScript file (lib/use-fetch.ts) with copy of useFetch() function.

  2. Add custom parseResponse() function:

    import type { FetchOptions } from 'ohmyfetch';
    
    /**
     * Parse response
     * @description Replace of `destr()` function to prevent memory leak
     * @param responseText
     */
    const parseResponse: FetchOptions['parseResponse'] = (responseText) => {
      // Send empty string if zero length
      if (responseText.length === 0) {
        return '';
      }
    
      try {
        return JSON.parse(responseText);
      } catch (_e) {
        return responseText;
      }
    };
    
  3. Replace _fetchOptions constant in the copy of useFetch() function:

      const _fetchOptions = {
        ...opts,
        parseResponse,
        cache: typeof opts.cache === 'boolean' ? undefined : opts.cache
      }
    
  4. Use patched useFetch() function instead of build-in.

Because, right now there is no way to provide custom parseResponse() function as option of the useFetch() without error.

Best wishes, Sergey.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mrauhucommented, Sep 2, 2022

@dargmuesli it’s part of the Datadog APM.

The dd-trace-js package was used for tracing. Under the hood it’s using the @datadog/pprof package, fork of pprof.

The Datadog Continuous Profiler used for visualization.

1reaction
mrauhucommented, Jul 6, 2022

Higher memory usage is likely the overhead of regex checkers over a heavy payload.

API responses is nested tree JSON documents, 50—100 KB size.

What happens after max memory usage?

Restart of a container.

Do you auto restart?

Yes.

Also what is prod Node.js version?

Node.js 16.14.2, a Docker image based on the https://github.com/astefanutti/scratch-node.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Huge Memory leak If the "meta" option is set true #94 - GitHub
Yes, we resolved a memory leak in the linked PR. The current leak is due to using a Vue 3 library (vueuse/head) and...
Read more >
Nuxt huge memory usage / leakage and how to prevent
I was in the under standing that Vue.use is OK if it is not inside export functionally? On the #3 we use $nuxt.$on...
Read more >
Avoiding Memory Leaks - Vue.js
Memory leaks in Vue applications do not typically come from Vue itself, rather they can happen when incorporating other libraries into an application....
Read more >
Vue and Nuxt Performance Optimization Checklist
Read the comprehensive and in-depth technical article summarizing how to improve the site performance with efficient use of Vue.js and Nuxt.
Read more >
Memory Leak Nuxt On Build - ADocLib
js. Your project is considerably large. This is common in most of the node projects. Wrong auth, axios module configurations. There could be...
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