Skip to content

Bug: Possible memory leak when using real Vuex store in plugins #1787

Closed

Description

@rappjt

Describe the bug

I have a project with 8,000+ tests using mocha, many of which create a real Vuex store. Recently we have migrated to Vue3 and test-utils v2. After the upgrade a memory leak is causing the test suite to fail as it runs out of heap space. At this time it seems to be adding a plugin (store) when mounting causes the issue, though not fully sure if there is additional cleanup I must be doing that isn't mentioned in docs.

To Reproduce

I have created the HelloWorld project from vue-cli (webpack, vuex, mocha), and modified the one and only test in that project:

  1. Looped single test many times
  2. created a store and added to global.plugins for each test
    1. I used this example to create/add the store
describe('HelloWorld.vue', () => {
  for (let i = 0; i < 10000; i++) {
    it(`${i}`, () => {
      const store = createStore({
        state () {
          return {
            count: 0
          }
        },
        mutations: {
          increment (state) {
            state.count += 1
          }
        }
      })

      const msg = 'new message'
      const wrapper = shallowMount(HelloWorld, {
        props: { msg },
        global: {
          plugins: [store]
        }
      })
      expect(wrapper.text()).to.include(msg)
    })
  }
})

When I inspect this while running I can observe each test is leaking memory. Simply, not creating store and not pass in plugins, I no longer see the leak.

Expected behavior

Run entire test suite without getting out of heap exception.

Related information:

  • @vue/test-utils version: 2.1.0
  • Vue version: 3.2.39
  • node version: 14.18.1 and 16.17.1
  • vuex version 4.0.2
  • @vue/cli-plugin-* version ~4.5.19

Additional context

A few other things I have tested:

  • creating one store for all tests and setting with config.global.plugins = [store], still saw leak
  • created store but did not actually use in config.global.plugins or in shallowMount, did not see leak

Activity

  1. added
    bug
    on Sep 29, 2022
  2. changed the title [-]Bug: [/-] [+]Bug: Possible memory leak when using real Vuex store in plugins[/+] on Sep 29, 2022
  3. cexbrayat commented on Sep 30, 2022

    @cexbrayat
    Member

    @rappjt Thanks for raising this issue. Would you mind pushing your repro to a GitHub repo so someone can take an easy look?

  4. freakzlike commented on Sep 30, 2022

    @freakzlike
    Contributor

    Can you also try again with wrapper.unmount() or enableAutoUnmount? Maybe this makes a difference

  5. rappjt commented on Sep 30, 2022

    @rappjt
    Author

    @cexbrayat - Thank you for the quick response, here is a repo I hope will demonstrate the issue https://github.com/rappjt/vuejs-test-utils-plugin-vuex-memory-issue

    @freakzlike - Thanks for the suggestion, in my original project I am doing this and still see the issue. I didn't show this in original post as I was trying to make minimal changes to the original test from vue-cli. However, I added unmount in repo listed above and still see the issue

  6. freakzlike commented on Oct 4, 2022

    @freakzlike
    Contributor

    I was able to reproduce it within VTU tests and I could break it down to:

    private attachNativeEventListener(): void {

    The changes in #1793 have reduced the memory in my test case from ~700 MB to ~300 MB so there is still some more optimization needed

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions