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

Tests causing CI agents to run out of memory on cypress 8.2 & above #17853

Closed
vaibhavganatra opened this issue Aug 23, 2021 · 48 comments · Fixed by #22460
Closed

Tests causing CI agents to run out of memory on cypress 8.2 & above #17853

vaibhavganatra opened this issue Aug 23, 2021 · 48 comments · Fixed by #22460
Assignees

Comments

@vaibhavganatra
Copy link

vaibhavganatra commented Aug 23, 2021

Current behavior

The Azure CI Agent machine running out of memory when running cypress tests on 8.2 & above on Azure Pipeline CI agents (Linux OS). The cypress dashboard eventually times out as well.

<--- Last few GCs --->

[31:0x1c7300000000]  8599171 ms: Mark-sweep 1835.4 (2072.0) -> 1832.6 (2071.6) MB, 205.8 / 0.0 ms  (average mu = 0.263, current mu = 0.223) allocation failure scavenge might not succeed
[31:0x1c7300000000]  8599492 ms: Mark-sweep 1835.0 (2072.0) -> 1832.6 (2071.6) MB, 294.6 / 0.0 ms  (average mu = 0.166, current mu = 0.082) allocation failure scavenge might not succeed

<--- JS stacktrace --->

The Test Runner unexpectedly exited via a exit event with signal SIGSEGV

Please search Cypress documentation for possible solutions:

https://on.cypress.io

Check if there is a GitHub issue describing this crash:

https://github.com/cypress-io/cypress/issues

Consider opening a new issue.

----------

Platform: linux (Debian - 10.10)
Cypress Version: 8.3.0

Desired behavior

No response

Test code to reproduce

This has been consistently reproducible on 8.2 and 8.3. Running the same spec files on the same agents on version 8.1 and below works as expected.

Cypress Version

8.3

Other

No response

@cellog
Copy link

cellog commented Aug 23, 2021

a note: in a much earlier version of cypress, we fixed this by adding

  "numTestsKeptInMemory": 1,

to our cypress-ci.json, this may help if you're not already doing this

@vaibhavganatra
Copy link
Author

I tried that and it is still failing with the same error.

@stychu
Copy link

stychu commented Aug 30, 2021

I can observe similar issues since 8.2 and higher. My AZURE pipelines just run until the pipeline timeout occurs once I upgrade above 8.1.

On Cypress 8.1 everything works flawlessly

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Aug 30, 2021
@jennifer-shehane
Copy link
Member

Is everyone in this thread experiencing this issue in Azure only?

@jennifer-shehane
Copy link
Member

Could anyone run Cypress in debug mode mode and print the entire set of logs here?

@cupcakepanda89
Copy link

I experience this when running cypress in aws codebuild too

@VadimSkuratovskyi
Copy link

VadimSkuratovskyi commented Sep 10, 2021

@jennifer-shehane I've got the same issue with 8.3.1 on Azure Linux agents:

2021-09-10T08:46:44.512Z cypress:cli checking environment variables
2021-09-10T08:46:44.513Z cypress:cli checking if executable exists /home/vsts/.cache/Cypress/8.3.1/Cypress/Cypress
2021-09-10T08:46:44.514Z cypress:cli Binary is executable? : true
2021-09-10T08:46:44.515Z cypress:cli binaryDir is  /home/vsts/.cache/Cypress/8.3.1/Cypress
2021-09-10T08:46:44.515Z cypress:cli Reading binary package.json from: /home/vsts/.cache/Cypress/8.3.1/Cypress/resources/app/package.json
2021-09-10T08:46:44.517Z cypress:cli Found binary version 8.3.1 installed in: /home/vsts/.cache/Cypress/8.3.1/Cypress
2021-09-10T08:46:44.519Z cypress:cli could not read binary_state.json file at "/home/vsts/.cache/Cypress/8.3.1/binary_state.json"
2021-09-10T08:46:44.520Z cypress:cli {}
2021-09-10T08:46:44.520Z cypress:cli is Verified ? undefined
2021-09-10T08:46:44.520Z cypress:cli running binary verification check 8.3.1
It looks like this is your first time using Cypress: 8.3.1

 cypress:server:util:process_profiler current & mean memory and CPU usage by process group:
  cypress:server:util:process_profiler ┌─────────┬───────────────────┬──────────────┬──────────────────────────┬────────────┬────────────────┬──────────┬──────────────┬─────────────┐
  cypress:server:util:process_profiler │ (index) │       group       │ processCount │           pids           │ cpuPercent │ meanCpuPercent │ memRssMb │ meanMemRssMb │ maxMemRssMb │
  cypress:server:util:process_profiler ├─────────┼───────────────────┼──────────────┼──────────────────────────┼────────────┼────────────────┼──────────┼──────────────┼─────────────┤
  cypress:server:util:process_profiler │    0    │     'plugin'      │      2       │      '3757, 14814'       │   43.01    │     47.46      │  2574.7  │   1243.49    │   2654.23   │
  cypress:server:util:process_profiler │    1    │     'cypress'     │      1       │          '3354'          │     5      │      4.31      │  221.75  │    249.44    │    265.1    │
  cypress:server:util:process_profiler │    2    │ 'electron-shared' │      4       │ '3356, 3515, 3357, 3676' │   102.5    │     25.85      │  193.93  │    201.46    │   204.38    │
  cypress:server:util:process_profiler │    3    │    'Electron'     │      1       │         '14802'          │    0.05    │     14.75      │  118.04  │    242.54    │   712.32    │
  cypress:server:util:process_profiler │    4    │      'other'      │      2       │      '14832, 14833'      │     0      │       0        │   3.48   │     3.45     │    3.56     │
  cypress:server:util:process_profiler │    5    │      'TOTAL'      │      10      │           '-'            │   150.56   │     91.66      │ 3111.91  │    1919.5    │   3262.54   │
  cypress:server:util:process_profiler └─────────┴───────────────────┴──────────────┴──────────────────────────┴────────────┴────────────────┴──────────┴──────────────┴─────────────┘ +11s
  cypress:server:util:process_profiler current & mean memory and CPU usage by process group:
  cypress:server:util:process_profiler ┌─────────┬───────────────────┬──────────────┬──────────────────────────┬────────────┬────────────────┬──────────┬──────────────┬─────────────┐
  cypress:server:util:process_profiler │ (index) │       group       │ processCount │           pids           │ cpuPercent │ meanCpuPercent │ memRssMb │ meanMemRssMb │ maxMemRssMb │
  cypress:server:util:process_profiler ├─────────┼───────────────────┼──────────────┼──────────────────────────┼────────────┼────────────────┼──────────┼──────────────┼─────────────┤
  cypress:server:util:process_profiler │    0    │     'plugin'      │      2       │      '3757, 14814'       │   92.19    │      48.1      │ 2772.17  │   1265.33    │   2772.17   │
  cypress:server:util:process_profiler │    1    │     'cypress'     │      1       │          '3354'          │    0.95    │      4.26      │  222.39  │    249.05    │    265.1    │
  cypress:server:util:process_profiler │    2    │ 'electron-shared' │      4       │ '3356, 3515, 3357, 3676' │    0.48    │     25.49      │  193.93  │    201.36    │   204.38    │
  cypress:server:util:process_profiler │    3    │    'Electron'     │      1       │         '14802'          │    0.67    │     14.55      │  115.13  │    240.66    │   712.32    │
  cypress:server:util:process_profiler │    4    │      'other'      │      2       │      '14987, 14988'      │     0      │       0        │   3.41   │     3.45     │    3.56     │
  cypress:server:util:process_profiler │    5    │      'TOTAL'      │      10      │           '-'            │   94.29    │      91.7      │ 3307.03  │   1939.05    │   3307.03   │
  cypress:server:util:process_profiler └─────────┴───────────────────┴──────────────┴──────────────────────────┴────────────┴────────────────┴──────────┴──────────────┴─────────────┘ +10s

<--- Last few GCs --->

[3757:0x3f6200000000]   741154 ms: Scavenge 1998.0 (2061.2) -> 1996.5 (2063.2) MB, 14.8 / 0.0 ms  (average mu = 0.797, current mu = 0.427) allocation failure 
[3757:0x3f6200000000]   741216 ms: Scavenge 2000.4 (2063.2) -> 1999.0 (2067.2) MB, 29.4 / 0.0 ms  (average mu = 0.797, current mu = 0.427) allocation failure 
[3757:0x3f6200000000]   742915 ms: Mark-sweep 2004.3 (2067.5) -> 2001.3 (2074.0) MB, 1670.7 / 0.0 ms  (average mu = 0.650, current mu = 0.179) allocation failure scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

@ikrasnikov
Copy link

I have an Agular project and using Cypress for e2e testing. I also have an issue with memory.

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory 1: 0x108316625 node::Buffer::New(v8::Isolate*, char*, unsigned long, void (*)(char*, void*), void*) [/Users/maksim/Library/Caches/Cypress/8.3.1/Cypress.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]

To reproduce the problem I made test project
In my case, the problem goes when the 390+ test file is loading.

Platform: Ubuntu 20.4
NodeJs: 16.9.1
npm: 7.21.1
Cypress: 8.4.1
cypress-cucumber-preprocessor: 4.2.0

@stychu
Copy link

stychu commented Oct 12, 2021

Any updates? I wish I could upgrade from 8.1 as I can see significant performance boost but this issue forces me to be locked to 8.1

@ikrasnikov
Copy link

@stychu there is no such issue in 8.1?

@simongarciam
Copy link

Tried to upgrade from cypress 7.2.0 to 8.6.0 and also found that the tests started consuming more resources from version 8.2.0 onwards (I pretty much tried all versions in between).
Ended up pinning version to 8.1.0 but really want to go to at least 8.3.0 to upgrade chrome from version 88.

Testing React App + cypress 8.5.0 + chrome 94 in a container in pipeline using AWS using m5.xlarge instance, (16 GB ram). switching to a m5.2xlarge (32 GB) makes test pass but this just hides the problem and locally the spec with quite a bit of tests just crashes chrome.

Running headless, there's no log saying chrome crashed, cypress just hangs.
Running in headed mode, I can see he browser crash and cypress just hangs.

@stychu
Copy link

stychu commented Oct 15, 2021

@stychu there is no such issue in 8.1?

@ikrasnikov Yes I run 8.1 without the issues. As long as I try to bump it up to 8.2 and above all tests hang out and timeout azure pipeline.

@ikrasnikov
Copy link

@stychu thank you! But in my case did not help to decrease the version to 8.1. Still have the same issue after 390 test file.

@stychu
Copy link

stychu commented Nov 17, 2021

Any updates? Is it working ?

@BlueWinds
Copy link
Contributor

Vadim's logs suggest that it's the plugins child process which is consuming memory, which is very helpful in at least giving us a place to start looking.

It's very strange that this begins occurring between 8.1 and 8.2. If 8.2 ran but 8.3 had issues, there'd be a variety of possible culprits (starting with the bundled electron and node versions), but 8,2 doesn't have anything that immediately jumps out at me as a potential cause.

9.0.0 does contain an electron and bundled node version bump, it might be worth trying. It also now uses nodeVersion: 'system' as the default rather than bundled as it used to.

@ikrasnikov
Copy link

@BlueWinds, tried with version 9.0.0. No changes. Run fails on 295 test file.
Here is the test project where the problem is reproduced

@BlueWinds
Copy link
Contributor

@BlueWinds, tried with version 9.0.0. No changes. Run fails on 295 test file. Here is the test project where the problem is reproduced

Thank you for the reproducible example! Having an easy way for us to reproduce issues is always the first step in figuring things out. 👍

@chrisbreiding - This is an ongoing issue I looked at last time and had to pass on because we didn't have good repro steps.

@ikrasnikov
Copy link

ikrasnikov commented Nov 23, 2021

@BlueWinds but have already posted this test project before, in my comment Sep 24 :)

@BlueWinds
Copy link
Contributor

@BlueWinds but have already posted this test project before, in my comment Sep 24 :)

Yeah, I see it now. Lots of issues to keep up with and not enough time to give them all the attention they deserve.

@LoaderB0T
Copy link

I have the same issue with a self-hosted Azure DevOps Agent. Fails after about 300 tests. Downgrading to 8.1.0 resolved the issue.

Interestingly enough, this issue was not always there with this version. It appeared out of nowhere months after updating to 8.4 but was persistent ever since.

@cupcakepanda89
Copy link

Do we have any update on this will be fixed soon 😢

@emilyrohrbough
Copy link
Member

Appears to be related to: #15508

@vaibhavganatra
Copy link
Author

We have been stuck on 8.1 due to this issue. Can someone please prioritze this issue?

@ikrasnikov
Copy link

ikrasnikov commented Jan 25, 2022

Tried to update to actual versions

"cypress": "9.3.1",
"cypress-cucumber-preprocessor": "4.3.1",
"typescript": "4.5.5"

Pushed changes to the test project.
Still have the same issue

@jeffchew
Copy link

This just started happening in my project, currently only in a particular PR so trying to troubleshoot it and came across this issue. One of the test runs (in Github Actions):

https://github.com/carbon-design-system/carbon-for-ibm-dotcom/runs/4970182640?check_suite_focus=true

This is the PR where this is happening (carbon-design-system/carbon-for-ibm-dotcom#8147), if it helps to see if a particular change is causing this. Our project was running fine on cypress v9.2.1 before this PR. Upgrading to latest version (9.3.1) didn't seem to help anything.

@testerswieton
Copy link

testerswieton commented Jan 27, 2022

If you want a solution for:
"[3078:0127/180408.450621:ERROR:node_bindings.cc(143)] Fatal error in V8: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory"

  1. Update the node version in Dockerfile eg:
    FROM node:17.3-slim

  2. Add memory for NODE in the docker-compose file used by GHA:
    services:
    cypress:
    environment:

    • NODE_OPTIONS="--max-old-space-size=8192"

@jeffchew
Copy link

If you want a solution for: "[3078:0127/180408.450621:ERROR:node_bindings.cc(143)] Fatal error in V8: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory"

  1. Update the node version in Dockerfile eg:
    FROM node:17.3-slim

  2. Add memory for NODE in the docker-compose file used by GHA:
    services:
    cypress:
    environment:

    • NODE_OPTIONS="--max-old-space-size=8192"

Thanks, I'm not using docker though, just running cypress tests on a node project in Github Actions. I can't upgrade node since our project has some dependency limitations at the moment.

I tried NODE_OPTIONS but that didn't work.

@jeffchew
Copy link

Just an update, I rolled my project back to Cypress 8.1 for now until this can be resolved. All tests run fine on that version.

@1r00t
Copy link

1r00t commented Apr 29, 2022

I have enough memory (32GB). My cypress runs in WSL2 and crashes as soon as maxMemRssMb reaches ~3500MB. I tried various ways to give it more memory but nothing seems to work.
I tried --max_old_space_size=16384 on chrome.
I tried increasing memory in .wslconfig
and much more. Nothing helps

@DJSdev
Copy link
Contributor

DJSdev commented Jun 3, 2022

Out of curiosity, I saw the note on the v10.0.0 release notes that a memory leak was fixed for e2e tests run using cypress run. Can anyone confirm if updating to v10+ resolved this issue? Someone at cypress maybe? @brian-mann

Related pull request: #19915

Release notes: https://docs.cypress.io/guides/references/changelog#10-0-0

@L4B0MB4
Copy link

L4B0MB4 commented Jun 13, 2022

I got a out of memory exception in Chrome running on Cypress v10.1.0. Already have the "keep one test in memory" option enabled. Switched to edge and ran a few test files. Started with around 1GB memory usage and am now on steady 4GB (only running cypress and nothing more on edge). Its definitely seems like a memory leak as it just does not free the memory even after finishing a test run

@stychu
Copy link

stychu commented Jun 14, 2022

Doesnt seem like the issue is fixed. I will check in azure in a moment but locally after migrating to cypress 10 when running the test my MAC is skyrocketing with CPU usage and it spins off the fans like crazy where as on 8.1 its quiet like a baby.
280% CPU usage for cypress process

@intellix
Copy link

intellix commented Jun 14, 2022

Could this be caused by this? nodejs/node#35889 (comment) - which has troubled Jest users for a long time as well

@stychu
Copy link

stychu commented Jun 14, 2022

As I though and process just hangs. This happens on azure alto there are some console errors which were not present in versions between 8.2 and 10


[30:0614/123746.553614:ERROR:zygote_host_impl_linux.cc(263)] Failed to adjust OOM score of renderer with pid 201: Permission denied (13)
[201:0614/123746.588096:ERROR:sandbox_linux.cc(377)] InitializeSandbox() called with multiple threads in process gpu-process.
[201:0614/123746.592132:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.
Couldn't find tsconfig.json. tsconfig-paths will be skipped
Couldn't determine Mocha version

================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        10.1.0                                                                         │
  │ Browser:        Electron 100 (headless)                                                        │
  │ Node Version:   v14.17.0 (/usr/local/bin/node)                                                 │
  │ Specs:          12 found (...)                                                                            │
  │ Searched:       cypress/tests/integration/**/*.ts                                              │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

-----> Cleaning cypress/reports <-----

────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running:  ....                                                                (1 of 12)
[30:0614/123750.070030:ERROR:zygote_host_impl_linux.cc(263)] Failed to adjust OOM score of renderer with pid 406: Permission denied (13)
[30:0614/123750.287987:ERROR:cert_verify_proc_builtin.cc(681)] CertVerifyProcBuiltin for redirector.gvt1.com failed:
----- Certificate i=0 (OU=Cypress Proxy Server Certificate,O=Cypress Proxy CA,L=Internet,ST=Internet,C=Internet,CN=redirector.gvt1.com) -----
ERROR: No matching issuer found


[30:0614/123750.419943:ERROR:cert_verify_proc_builtin.cc(681)] CertVerifyProcBuiltin for app failed:
----- Certificate i=0 (OU=Cypress Proxy Server Certificate,O=Cypress Proxy CA,L=Internet,ST=Internet,C=Internet,CN=app) -----
ERROR: No matching issuer found


[30:0614/123751.069481:ERROR:cert_verify_proc_builtin.cc(681)] CertVerifyProcBuiltin for ... failed:
----- Certificate i=0 (OU=Cypress Proxy Server Certificate,O=Cypress Proxy CA,L=Internet,ST=Internet,C=Internet,CN=r...) -----
ERROR: No matching issuer found

@stychu
Copy link

stychu commented Jun 21, 2022

Come-on we need this to be fixed ASAP there are multiple features from Cypress v10 that would simplify so much things and I want to use them but Im unable to due this bug.... @cellog @jennifer-shehane

@DJSdev
Copy link
Contributor

DJSdev commented Jun 21, 2022

Hey, my company has this issue too and I think I found the cause and am close to having a PR ready to fix this.

Setup

In my environment, I found this out of memory issue only happens in Chrome, it doesn't seem to occur in FireFox. Hopefully someone might be able to confirm this for me, as this would make me hopeful my fix solves this issue.

According to Task Manager, Cypress's server was growing to multiple GB in size, so I added some code to make Cypress dump its server's heap memory every 90 seconds. In the contents of that, I found a memory leak and I hope it's the one related to this issue.

Investigation

In the memory dump, I found Cypress was storing hundreds (maybe thousands) copies of the same base64 encoded string in an array named pendingBrowserPreRequests.
image

I looked at my company's app and found a css file that has the base64 font file in question hardcoded as the src field.
image

Side note: this issue could be remedied on the application side if base64 font files are removed from css files and changed to urls.

Root Cause

Cypress subscribes to the CDP event Network.requestWillBeSent and adds network requests that will be sent to an array. The elements in the array are removed when the corresponding response for the request comes back.

With these fonts inside the URL field of css stylesheets, this triggers Chrome to send a Network.requestWillBeSent event to Cypress with the URL of the request being the entire base64 encoded font file (lol). These requests are not actually going to be sent from the browser as it will parse these values instead, so Cypress never knows when to release these from its array since it never sees a response. It could be argued that this is a Chrome issue, but the fix should be relatively simple on the Cypress side.

I think I can have a PR out tomorrow to fix.

cc: @jennifer-shehane @brian-mann

@BlueWinds
Copy link
Contributor

@DJSdev - Jennifer's currently on leave, so she won't be around to address this, but I'm certainly interested! Please ping me on your PR when you have it ready, I'll make sure it gets the team's attention ASAP.

@DJSdev
Copy link
Contributor

DJSdev commented Jun 22, 2022

@BlueWinds PR is out!

@cypress-bot cypress-bot bot added stage: routed to e2e-core and removed stage: needs review The PR code is done & tested, needs review labels Jun 22, 2022
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 23, 2022

The code for this is done in cypress-io/cypress#22460, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 28, 2022

Released in 10.3.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v10.3.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jun 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet