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

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

Closed
rappjt opened this issue Sep 29, 2022 · 4 comments · Fixed by #1793
Closed

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

rappjt opened this issue Sep 29, 2022 · 4 comments · Fixed by #1793
Labels
bug Something isn't working

Comments

@rappjt
Copy link

rappjt commented Sep 29, 2022

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
@rappjt rappjt added the bug Something isn't working label Sep 29, 2022
@rappjt rappjt changed the title Bug: Bug: Possible memory leak when using real Vuex store in plugins Sep 29, 2022
@cexbrayat
Copy link
Member

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

@freakzlike
Copy link
Collaborator

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

@rappjt
Copy link
Author

rappjt commented Sep 30, 2022

@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

@freakzlike
Copy link
Collaborator

freakzlike commented Oct 4, 2022

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
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants