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
Fast memory leak/creep when cy.get fails to find the element, and eventually crashes #18549
Comments
Can someone take a look? I can provide more info if needed |
ping @jennifer-shehane |
Thanks for the report (with easy to follow repro steps! <3) and the bump, this is indeed a serious issue. I played with this a bit, and you're definitely right that there's a serious memory leak. All my tests are in Cypress 9.0.0. Some results:
Some initial debugging:
So basically: Commands that continually query the DOM seem to be causing issues in non-Firefox browsers. I'll make sure someone on the team looks into it - there are several other issues open recently that this might be a root cause for. Edit: Inspired by #17853, I tried this back on Cypress 8.1.0, with the same results - memory leak is also present there. |
Awesome! thanks for looking into this! |
Poking around here further, it's because of DOM snapshotting. Whenever an assertion fails (badSelector doesn't exist on the page), we call In Firefox, these snapshots get cleaned up efficiently, but in the current electron version (and certain chromium / chrome versions) they stick around in memory. While it might be possible to clean up the snapshots better, I'm still investigating why we make dozens of copies of the DOM per second. Even if they're GCed regularly, it still seems wasteful. Leaking memory at 100mb / second means that we're allocating memory at 100mb / second. All this is fairly deem in the Cypress internals, and not easy to debug / change regardless. |
So a bit of an update here - the retries were the dragon's tail. Tug it, and you get not a snake but a dragon nesting in the depths of the codebase with its treasure horde and toothy grin. I've updated the attached PR with a better solution, which should reduce unnecessary DOM snapshotting in any situation where implicit assertions that an element exists in the DOM fail - including temporarily while we're waiting for an element to be actionable in tests that eventually pass. |
The code for this is done in cypress-io/cypress#19311, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior
While cy.get() retries to find an element , the memory usage of the tab shoots up quickly
See video https://youtu.be/N5jtyBdd05Q
Desired behavior
Memory usage should not increase this quickly
Test code to reproduce
describe('Memory issue', () => {
it('Simple memory test', () => {
cy.visit('https://www.androidpolice.com')
cy.get('.garbageId')
})
})
Cypress Version
5.1.0 and latest 8.6.0
Other
Initially I found this issue while testing my company's website, then I found that it is easily reproducible with other websites as well
Pre-requisistes
Steps to reproduce
As you can see in the video linked above, the memory usage starts shooting up when Cypress is trying to find the element.
When you re-run the test without closing the tab, the memory doesn't reset and keeps adding up. Eventually when the usage reaches 4GB, the tab crashes with the "Aw snap" message.
This issue is a lot more apparent if the test is longer with more steps, which can put the memory usage close to the ceiling of 4GB.
So far the reliable workaround is to set numTestsKeptInMemory to 0, which stops the memory creep altogether.
Very occasionally I can observe the garbage collection kicking in and reducing the memory usage, however the cy.get() still rapidly increases the memory usage after
The text was updated successfully, but these errors were encountered: