Vee-validate: localeChanged memory leak with nuxt SSR

Created on 9 Jun 2018  Â·  4Comments  Â·  Source: logaretm/vee-validate

Versions

  • vee-validate: 2.0.9
  • vue: 2.5.13
  • nuxt: 1.4.0

Describe the bug
A 72 byte (If I'm reading this correctly) memory leak caused our server to crash after 3 days

To Reproduce
Steps to reproduce the behavior:

  1. Go to a nuxt project with vee-validate
  2. Click on the start button
  3. Click on the spam button (autocannon -c 100 -d 120 http://localhost:3000)
  4. Watch memory increase some megabytes

Expected behavior
No crashing servers

Demo Link
No demo repo. It's friday at 5pm. If it's needed, I can create one.

Desktop (please complete the following information):

  • OS: elementary OS juno
  • Browser: Chrome
  • Version: 67.0.3396.62 (Official Build) beta (64-bit)

Additional context

AWS memory graph for that server:
screenshot from 2018-06-08 16 59 04

Viewing heap snapshots before and after:
screenshot from 2018-06-08 16 59 48

Screenshot of Vue instance data:
screenshot from 2018-06-08 17 00 36

✨ enhancement 💨 performance

Most helpful comment

I applied a small fix which should patch the issue temporarily.

A major rewrite is in progress which will employ a single validator instance for the entire app since there is no real benefit of multiple instances except for scoping fields within components.

All 4 comments

Maybe this?

::: warning With SSR Frameworks like Nuxt, it is recommended to disable automatic injection since it may cause memory leaks due to all the validator instances being created for every component, which will slow down your site. :::

Injection is disabled.

The file is a little messy. Sorry.

/**
 * artoo/plugins/validation.js
 * Registers vee-validate. We import the minimal build and only import the rules
 * we need. This brings the bundle size down around 50kb.
 *
 * TODO: When vee-validate gets more module, bring this into the component that
 * needs them.
 */

import Vue from 'vue'
import VeeValidate from 'vee-validate'

/**
 * TODO: When PR#1264 gets released we can bring the bundle size down about
 * 50kb.
 *
 * https://github.com/baianat/vee-validate/pull/1264/files
 *
import VeeValidate from 'vee-validate/dist/vee-validate.minimal.esm.js'

import {
  credit_card,
  max_value,
  max,
  min_value,
  min,
  required
} from 'vee-validate/dist/rules.esm.js'

VeeValidate.Validator.extend(credit_card)
VeeValidate.Validator.extend(max_value)
VeeValidate.Validator.extend(max)
VeeValidate.Validator.extend(min_value)
VeeValidate.Validator.extend(min)
VeeValidate.Validator.extend(required)
*/

Vue.use(VeeValidate, {
  inject: false,
})

It should remove the added listeners when the vm is being destroyed. Will investigate and report back

I applied a small fix which should patch the issue temporarily.

A major rewrite is in progress which will employ a single validator instance for the entire app since there is no real benefit of multiple instances except for scoping fields within components.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

7immer picture 7immer  Â·  3Comments

Youdaman picture Youdaman  Â·  3Comments

Hoagiex picture Hoagiex  Â·  3Comments

MeltedFreddo picture MeltedFreddo  Â·  3Comments

schel4ok picture schel4ok  Â·  3Comments