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

Javascript heap out of memory #22419

Closed
Chili82 opened this issue Jun 21, 2022 · 21 comments
Closed

Javascript heap out of memory #22419

Chili82 opened this issue Jun 21, 2022 · 21 comments
Assignees
Labels
stage: awaiting response Potential fix was proposed; awaiting response type: bug

Comments

@Chili82
Copy link

Chili82 commented Jun 21, 2022

Current behavior

Hi, I have about 200 scenarios in 15 feature files and in headless mode (electron) every time I get a memory issue error (approx after 90 min from the start of tests).

image

I've set env variable in cypress.env.json but this setup is not resolved this problem.
image

image

My company is interested in buying a cypress license but this is our blocker. We also went through the whole code and did the optimization, each test is completed in about 30 - 50 seconds but we still have a problem. Please who can help with this serious issue

Desired behavior

No response

Test code to reproduce

{
"NODE_OPTIONS": "--max_old_space_size=8192",
"ELECTRON_EXTRA_LAUNCH_ARGS":"--js-flags=--expose_gc"
}

Cypress Version

9.4.1

Other

No response

@mjhenkes
Copy link
Member

This may be fixed by #22460

@cypress-bot cypress-bot bot added the stage: investigating Someone from Cypress is looking into this label Jun 22, 2022
@Chili82
Copy link
Author

Chili82 commented Jun 23, 2022

Thanks, is this fix available in 10.2.0?

@mjhenkes
Copy link
Member

we plan to release it tomorrow.

@Chili82
Copy link
Author

Chili82 commented Jun 23, 2022

Thank You!

@mjhenkes
Copy link
Member

this might be next week.... sorry 😓

@mjhenkes
Copy link
Member

Could you try the 10.3.0 release? We fixed a memory leak that might be causing this issue.

@cypress-bot cypress-bot bot added stage: awaiting response Potential fix was proposed; awaiting response and removed stage: investigating Someone from Cypress is looking into this labels Jun 28, 2022
@Chili82
Copy link
Author

Chili82 commented Jun 29, 2022

Yes, I will try today and let you know more inforamtion.

@Chili82
Copy link
Author

Chili82 commented Jun 29, 2022

I've run all tests with 10.3.0 version, and also I've migrated the solution but after each test, the application instance is killed and the next test has a problem with the state of the application. This wasn't the case with previous versions 9 and 8.

@cypress-bot cypress-bot bot added stage: investigating Someone from Cypress is looking into this and removed stage: awaiting response Potential fix was proposed; awaiting response labels Jun 29, 2022
@Chili82
Copy link
Author

Chili82 commented Jun 29, 2022

Additional information: - seems that the test clears some flags from local storage during executing steps (usually the first step for login to application).

@lmiller1990
Copy link
Contributor

lmiller1990 commented Jun 30, 2022

90 minutes is one heck of a long run. Over that time, I'm guessing there's a memory leak somewhere that's eventually causing this issue.

Just to clarify; you run all tests specs, sequentially, on your local machine (as opposed to a CI machine)?

This wasn't the case with previous versions 9 and 8.

Your post says you are on 9.4.1 - can you confirm this issue is happening on 9.4.1, or only since migrating to 10? My understanding is this was not happening with older versions of Cypress 9, but is now happening on Cypress 9.4.1?

Since moving to Cypress 10, is it the same, or a different problem? You mention "but after each test, the application instance is killed and the next test has a problem with the state of the application" - which seems like, since moving to Cypress 10, there's a different issue?

So, please clarify:

  1. original issue - Cypress 8 and 9.x is okay, but as of 9.4.1, you get the memory error.
  2. new issue - since moving to Cypress 10, you have a different problem, where the "application instance is killed". What exactly does this mean - are you saying the Cypress application is killed?

@lmiller1990 lmiller1990 added stage: awaiting response Potential fix was proposed; awaiting response and removed stage: investigating Someone from Cypress is looking into this labels Jun 30, 2022
@Chili82
Copy link
Author

Chili82 commented Jun 30, 2022

Yes sorry, on 9.4.1 I get an error without memory. After that, I installed version 10.3.0 and ran all the tests, but after a few tests my tests started to crash and I can't fully test if we still have out of memory.
The application we are testing works on the following principle:

  • when the user logs in, we place the appropriate settings in localStorage. After each user action, we refresh the localStorage and sequentially every 5 seconds pull the state from the localStorage and send the request to the database.
    We have a cypress test that simulates the user's login, the user then changes the state of the form and checks the appropriate parameters.
    The problem is that in the step after logging the user I see that the localStorage is initially loaded but when the next step starts eg the user enters some value in the input field, the values ​​in localStorage are deleted and the logic that every 5 seconds should take the state from localStorage does not work because the parameter in localStorage = null and the state of the application is not valid.
    It seems to me that cypress affects localStorage during the execution of steps in one scenario, which was not the case in earlier versions 9 and 8.

I will try to determine exactly what the reason is but I am not sure if the reason is cypress or the problem is in the application but the same application when I run on 8.1 or 9.4.1 we have no problem with localStorage.

When we solve this problem with localStorage then I can run all the tests and check if the problem with out of memory has been fixed.

8.1 version works correct (there is no problem with either memory or localStorage).

@lmiller1990
Copy link
Contributor

Thanks for the reply. Let's start with the latter issue, around localStorage in Cypress 10. We generally don't patch older versions, like 9.4.1, so I think it's best to focus on the 10.x issue first, and go from there.

The problem is that in the step after logging the user I see that the localStorage is initially loaded but when the next step starts eg the user enters some value in the input field, the values ​​in localStorage are deleted and the logic that every 5 seconds
It seems to me that cypress affects localStorage during the execution of steps

So to clarify, when you say a step you are referring to a command, eg cy.get, cy.click etc (functions on the cy object)? We do clear local storage before each test (so each it block) but this has not changed between v9 and v10.

we refresh the localStorage and sequentially every 5 seconds pull the state from the localStorage

Is there any chance of a minimal reproduction? What do you mean by "refresh" here?

Sorry for all the questions - I'm trying to understand what I need to do to actually reproduce this. Happy to go back and forth, but it might be quicker if you can share a minimal reproduction - it sounds like the issue doesn't need a server/backend application at all - instead of logging in, you could just create a project that sets the local storage in a before hook, or something to that meaning.

@cypress-bot cypress-bot bot added stage: fire watch stage: awaiting response Potential fix was proposed; awaiting response and removed stage: awaiting response Potential fix was proposed; awaiting response stage: fire watch labels Jul 1, 2022
@Chili82
Copy link
Author

Chili82 commented Jul 1, 2022

Yes, I know that cypress clears localStorage after each test but if I have one test with few steps (login, open custom form, customize form - add new input or checkbox on the form, set some values on a form and save for example)

When user login
Then open custom form
And add new input on form
And add new checkbox on form
And save form template
.....
This is one pseudo-gherkin scenario.

When I say "refresh" localStorage, I mean update localStorage with new applicationState (current arrangement of elements on the form, the appearance of the form). After login, we get the state from DB and save this data in localStorage. If the user adds a new form or new element to the form, we update localStorage with a new applicationState. In the background, we have a function that periodically fetches the value from localStorage and saves it to DB (every 5 seconds).

Problem is following:

  • When executing login step (When user login), the user is logged in and we get default data for applicationState from DB and correctly it to save in localStorage, after that we have a second step (Then open custom form). This step was performed correctly, our application in background correctly updates localStorage because a new form is opened and the applicationState is changed, but suddenly localStorage is empty and we cannot take data from it because it is empty and our application returns an error dialog that the state is not valid and the test cannot until the end to be fulfilled.
    We use cy.get() to reference elements from the form in every step from one test, but my question is the following:
    is there a possibility that cypress affects localStorage after performing a one step within the same test (for example after step "Then open custom form")?

@Chili82
Copy link
Author

Chili82 commented Jul 7, 2022

Yes, I know that cypress clears localStorage after each test but if I have one test with few steps (login, open custom form, customize form - add new input or checkbox on the form, set some values on a form and save for example)

When user login Then open custom form And add new input on form And add new checkbox on form And save form template ..... This is one pseudo-gherkin scenario.

When I say "refresh" localStorage, I mean update localStorage with new applicationState (current arrangement of elements on the form, the appearance of the form). After login, we get the state from DB and save this data in localStorage. If the user adds a new form or new element to the form, we update localStorage with a new applicationState. In the background, we have a function that periodically fetches the value from localStorage and saves it to DB (every 5 seconds).

Problem is following:

  • When executing login step (When user login), the user is logged in and we get default data for applicationState from DB and correctly it to save in localStorage, after that we have a second step (Then open custom form). This step was performed correctly, our application in background correctly updates localStorage because a new form is opened and the applicationState is changed, but suddenly localStorage is empty and we cannot take data from it because it is empty and our application returns an error dialog that the state is not valid and the test cannot until the end to be fulfilled.
    We use cy.get() to reference elements from the form in every step from one test, but my question is the following:
    is there a possibility that cypress affects localStorage after performing a one step within the same test (for example after step "Then open custom form")?

@lmiller1990
Copy link
Contributor

but my question is the following: is there a possibility that cypress affects localStorage after performing a one step within the same test (for example after step "Then open custom form")?

Cypress will only clear localStorage before each test - we don't do anything specific during the test, so unless your test case is modifying localStorage, it will not change.

@GeorgeousPRO
Copy link

Hi, I also get Heap out of memory when running tests on CI.
In process_profiler table I see group called 'plugin' is growing in size with each test and eventually it breaks
image
@lmiller1990 any ideas why 'plugin' group is taking up so much resources?
I tried updating all plugins to last versions, but it didn't help

@mjhenkes mjhenkes assigned astone123 and unassigned lmiller1990 Jul 11, 2022
@cypress-bot cypress-bot bot added stage: investigating Someone from Cypress is looking into this and removed stage: awaiting response Potential fix was proposed; awaiting response labels Jul 11, 2022
@lmiller1990
Copy link
Contributor

Oh nice debugging! This is useful. The cypress.config.js runs in a different process, so if you are modifying it and break it, your entire Cypress app won't crash - once you fix it, we re-execute it for you (on save, for example).

What plugins are you using? Either

  1. one of them is leaking resources
  2. something in our logic is leaking resources

If it's the latter, we can definitely fix it, need to figure out what's going on. If I was debugging, I'd incrementally remove plugins and try to isolate which one(s) might be causing this.

@GeorgeousPRO
Copy link

in our case the issue turned out the 'ts-loader' version "5.3.3". Once updated to "8.1.0" the memory leak got fixed.

@lmiller1990
Copy link
Contributor

Nice - always good to update dependencies, glad that fixed it for you. I wonder if it can help the OP.

@nagash77 nagash77 assigned mjhenkes and unassigned lmiller1990 Jul 19, 2022
@mjhenkes
Copy link
Member

@Chili82, Could you check your version of ts-loader to see if it needs to be updated?

@cypress-bot cypress-bot bot added stage: awaiting response Potential fix was proposed; awaiting response and removed stage: investigating Someone from Cypress is looking into this labels Jul 19, 2022
@Chili82
Copy link
Author

Chili82 commented Jul 20, 2022

Yes, I will check as soon as possible. Currently I'm on vacation, but I will let you know next week. Thank you

@mjhenkes mjhenkes closed this as completed Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: awaiting response Potential fix was proposed; awaiting response type: bug
Projects
None yet
Development

No branches or pull requests

7 participants