Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt memory leak universal mode #7915

Closed
WilliamDASILVA opened this issue Aug 13, 2020 · 3 comments
Closed

Nuxt memory leak universal mode #7915

WilliamDASILVA opened this issue Aug 13, 2020 · 3 comments

Comments

@WilliamDASILVA
Copy link

Versions

  • nuxt: 2.14.1
  • node: 10.16.0

Reproduction

Additional Details

nuxt.config

module.exports = {
  mode: 'universal',
  srcDir: './src',
  server,
  head: {
    title: pkg.name,
    noscript: [{ innerHTML: 'This website requires JavaScript to run properly.' }],
    htmlAttrs: {
      dir: 'ltr'
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  css: [
    { src: '@/assets/scss/style.scss', lang: 'scss' }
  ],
  plugins: [
    '~/plugins/vee-validate.js'
  ],
  modules: [
    'nuxt-stripe-module',
    '@nuxtjs/style-resources',
    '@nuxtjs/axios',
    '@nuxtjs/sitemap',
    '@nuxtjs/sentry',
    '@nuxtjs/robots',
    ['vue-wait/nuxt', { useVuex: true }],
    ['@nuxtjs/google-analytics', {
      id: 'UA-TEST'
    }]
  ],
  stripe: {
    publishableKey: process.env.STRIPE_PUBLISHABLE_KEY || ''
  },
  sentry: {
    dsn: process.env.SENTRY_DSN || ''
  },
  sitemap: {
    path: '/sitemap.xml'
  },
  styleResources: {
    scss: [
      'assets/scss/_variables.scss',
      'assets/scss/_mixins.scss'
    ]
  },
  build: {
    transpile: [
      'vee-validate/dist/rules'
    ]
  },
  env: {
    appUrl: process.env.VUE_APP_APP_URL
  },
  axios: {
    baseURL: process.env.API_BASE_URL,
    browserBaseURL: process.env.API_BROWSER_BASE_URL
  },
  tailwindcss: {
    cssPath: '~/assets/css/tailwind.css'
  },
  buildModules: [
    '@nuxtjs/pwa',
    '@nuxtjs/tailwindcss'
  ]
}

store.js

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: () => ({}),
  actions: {},
  mutations: {},
  getters: {}
})

export default () => store

Steps to reproduce

I've build my Nuxt app that uses Vuex, then I sent a certain amount of requests to it, the memory usage keeps growing without coming down. At some point (approx. 4-6 hours in a normal usage, less than a minute during a stress-test), the server crashes because it runs out of memory.

Capture d’écran 2020-08-13 à 23 05 14

In this screenshot, you can see 2 snapshots. The first one is just after the server started. The second is after a 1 minute stress-test right after

By removing the lines in the .nuxt/index and .nuxt/dist/server/server.js:

  const registerModule = store.registerModule
  store.registerModule = (path, rawModule, options) => registerModule.call(store, path, rawModule, Object.assign({ preserveState: process.client }, options))

Then restarting the server and doing the same stress-test, I'm not getting the huge memory leak spike.

What is Expected?

I expect the server to live longer than some hours in production, in a real usage. I don't want to restart it everytime it crashes with a balancer to have a good uptime.

What is actually happening?

I'm getting a huge memory usage and the server keeps crashing.

@galvez
Copy link

galvez commented Aug 13, 2020

What is the value of NODE_ENV on your production environment?

@WilliamDASILVA
Copy link
Author

WilliamDASILVA commented Aug 14, 2020

@galvez My NODE_ENV is production. Even if I change the NODE_ENV to something else than production, I'm getting the same results.

"start:inspect": "NODE_ENV=production node --inspect=0.0.0.0 ./node_modules/nuxt-start/bin/nuxt-start.js",

My quick-dirty-bandaid fix/workaround was to remove the usage of the registerModule by adding a new plugin that would delete that function, since I'm quite sure I'm not using it anywhere.

/**
 * Bandaid to resolve the issue with store.registerModule
 * since we're not using registerModule anywhere.
 */
export default ({ store }) => {
  delete store.registerModule
}

The same test with my workaround:

Capture d’écran 2020-08-14 à 02 12 33

pi0 pushed a commit that referenced this issue Aug 15, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@pi0 pi0 mentioned this issue Aug 16, 2020
@galvez
Copy link

galvez commented Aug 16, 2020

@WilliamDASILVA should be fixed in latest Nuxt release.

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

No branches or pull requests

3 participants