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

Chrome browser hangs due to potential memory leak caused by failing tests #30664

Open
FrancisBourgault opened this issue Nov 21, 2024 · 3 comments
Labels
stage: needs investigating Someone from Cypress needs to look at this type: performance 🏃‍♀️ Performance related

Comments

@FrancisBourgault
Copy link

FrancisBourgault commented Nov 21, 2024

Test code to reproduce

Command to run the tests

set DEBUG=cypress*memory && set CYPRESS_INTERNAL_MEMORY_SAVE_STATS=1 && set CYPRESS_NO_COMMAND_LOG=1 && tsc && cypress run --config-file cypress.dev.config.js --browser chrome --headless

Configuration file

// cypress.dev.config.ts
import { defineConfig } from 'cypress'

module.exports = defineConfig({
  video: false,
  e2e: {
    screenshotOnRunFailure: false,
    numTestsKeptInMemory: 0,
    testIsolation: true,
    experimentalMemoryManagement: true,
    baseUrl: "http://localhost:5173",
    supportFile: "./cypress/support/e2e.js",
    specPattern: "./cypress/e2e/**/*.cy.js"
  },
});

// Test file

// testFile.cy.ts
describe('Test File', () => {

    context("Test Suite", { viewportWidth: 1920, viewportHeight: 1080 }, function() {

        function setUpAndNavigate() {
            cy.visit("http://localhost:5173");

            // May not be necessary
            return cy.wait(500);
        }

        // Depending on your available memory, it may take more or less tests to crash the browser. Adjust the number of loops in the code if necessary.
        for (let i = 0; i < 1000; ++i) {

            it(`Success Test number ${i}`, function() {
                setUpAndNavigate();

                cy.get("#root h1").should("be.visible");
            });

            it(`Fail Test number ${i}`, function() {
                setUpAndNavigate();

                cy.get("#root h1", { timeout: 1}).should("not.exist", { timeout: 1});
            });
        }
    });
});

Cypress Mode

cypress run

Cypress Version

13.16.0

Browser Version

Chrome 131.0.6778.71

Node version

20.9.0

Operating System

Windows 11

Memory Debug Logs

See 2nd comment (logs too big to be uploaded in this section)

Other

More details on the issue

Every time a test fails, the memory usage increases. If you comment the fail tests, and run only the success tests (you can double the amount of loops so the number of tests stays the same), the memory usage won't increase.

This impacts CI run that contains bigger spec files. If any of the big spec file freeze due to that memory issue, none of the other remaining spec files will be run.

  • This issue also happens on Electron, but Electron will crash and move on to the next spec file. Chrome will hang forever. This is the message displayed by Electron:
We have failed the current spec but will continue running the next spec.

This can happen for a number of different reasons.

If you're running lots of tests on a memory intense application.
   - Try increasing the CPU/memory on the machine you're running on.
   - Try enabling experimentalMemoryManagement in your config file.
   - Try lowering numTestsKeptInMemory in your config file during 'cypress open'.

You can learn more here:

https://on.cypress.io/renderer-process-crashed
  • This issue happens on 3 different type of applications (Craco React, Vite React, Angular), so the type of app does not matter.
  • Replacing the "for" loop with copies of the test also cause the issue
  • This issue happens whether testIsolation is set to true or false.
  • This issue happens whether experimentalMemoryManagement is set to true or false.
  • This issue happens whether CYPRESS_NO_COMMAND_LOG is set to 1 or 0

Setting up a small app to test this issue

  • To create a small app to quickly test this issue, run this command:
npm create vite@latest
  Project name: <any name>
  Select a framework: React
  Select a variant: TypeScript
  • Run "npm run dev" to launch the Vite-React application. Set the url into your cypress.config.ts file.
@FrancisBourgault
Copy link
Author

FrancisBourgault commented Nov 21, 2024

Partial memory logs here (include performance in the middle of the test run, as well as the last test):

CypressMemoryLog.txt

@ryanthemanuel
Copy link
Collaborator

Hi @FrancisBourgault. I see that you are on 13.6.0. Have you tried the latest version (13.16.0)? We've made some improvements since 13.6.0.

@FrancisBourgault
Copy link
Author

@ryanthemanuel sorry, that was a typo. The issue is on 13.16.0.

@jennifer-shehane jennifer-shehane added type: performance 🏃‍♀️ Performance related stage: needs investigating Someone from Cypress needs to look at this labels Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs investigating Someone from Cypress needs to look at this type: performance 🏃‍♀️ Performance related
Projects
None yet
Development

No branches or pull requests

3 participants