cypress: Do not display MaxListenersExceededWarning "Warning: Possible EventEmitter memory leak detected." warning message during cypress run

Current behavior:

After creating 8 spec files warning about EventEmitter memory leak appears (even if specs contain empty describe()). After ignoring this warning and continue creating more specs, last added specs don’t run, and appears FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

Desired behavior:

Number of spec files do not affect test run

How to reproduce:

  • Add cypress to project
  • At cypress/integration folder create 8 spec files with any content inside them it could be only describe('', () => {});
  • Run created tests using command: cypress run

Additional Info (images, stack traces, etc)

After adding 8th spec next warning appeared: memoryleakmessage

Even if there are no tests inside them zerotestwithmemoryleak

After ignoring this warning and creating more specs got this error: fatalerror

  • Operating System: Linux, MacOS
  • Cypress Version: both 1.4.2 and 1.4.1
  • Node version: 8.8.1

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 46
  • Comments: 96 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Can the Cypress team please update this issue?

I am new to Cypress and encountering a similar error on current Cypress, current macOS, 16G machine, with just a dozen or so tests running:

(node:40489) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exitEarlyWithErr listeners added. Use emitter.setMaxListeners() to increase limit

Thank you.

We are also seeing this on the 11th test…

#@brian-mann @jennifer-shehane @bahmutov First of all Many thanks for your continuous support and proving me with framework which has made our life easier when it comes to writing UI test cases. It’s light as compared to selenium. One has to write very minimal code to achieve something as compared to other automation framework in the market for example selenium. Lately out suite has grown gradually and when I updated my cypress version to 6.2.0 the issue of Memory leak and suite timeout issues ⚠️ didn’t allow the test cases to run successfully and added up the frustration because what 😦 is the use of so many test 💯 cases if you can not run them because of memory leak and timeout issues. Finally degraded back to cypress version 4.12.1 and ran cypress:run and all the 300 test cases ran successfully with no timeout and memory leak issue. @bahmutov we should be 🚫 new releases and start concentrating on the real issue because people are moving away to selenium as they afraid that such issues will make their whole efforts to zero because no one is able to run their suite headless on chrome and electron. Please 🙏 kindly 🔧 this issue on priority. So, that all the cypress users can start using it effectively and efficiently. Happy new Year.

We are aware of the warnings being displayed for Possible EventEmitter memory leak detected. and believe this to not be affecting the behavior or Cypress.

@jennifer-shehane This is simply not true. We see this on CI regularly and the result is often that tests hang until the job times out. No output to the console at all. If you run it locally on a well specced machine, then any effect is masked. However on a more resource-constrained CI runner, it (or whatever the underlying cause is) very much effects behaviour.

I’ve spent a few hours this evening trying to track down the cause of this error message - starting by slowly deleting chunks of our code until I’m left with a vary barebones cypress setup that still reproduces the issue. I’ve upgraded Cypress to the latest version (6.5) as well as Node (14 LTS).

All I have left is 11 spec files that contain a very dummy test (expect(true).to.be(true)), no other dependencies or code, and an empty cypress.json file.

I’ve published that repro here: clarkd/cypress-eventemitter-warning-repro

The output in the command line is as follows, note the warning towards the end of the output: (node:30568) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 preprocessor:close listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit

[personal] C:\Users\dave.clarke\Documents\Code Repository\saas\client\e2e-tests>  npm run run

> e2e-tests@1.0.0 run
> cypress run -b chrome -q




  Test 1
    √ This is a test (47ms)


  1 passing (85ms)



  Test 10
    √ This is a test


  1 passing (48ms)



  Test 11
    √ This is a test


  1 passing (50ms)



  Test 2
    √ This is a test


  1 passing (47ms)



  Test 3
    √ This is a test


  1 passing (42ms)



  Test 4
    √ This is a test


  1 passing (37ms)



  Test 5
    √ This is a test


  1 passing (45ms)



  Test 6
    √ This is a test


  1 passing (48ms)



  Test 7
    √ This is a test


  1 passing (48ms)

(node:30568) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 preprocessor:close listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit

  Test 8
    √ This is a test


  1 passing (48ms)



  Test 9
    √ This is a test


  1 passing (52ms)

At this point I’m kind of struggling to see how this is anything but a Cypress bug but would love any pointers to where I’m going wrong!

@jennifer-shehane - it would be great if you have chance to test out the above repro, and see if you can reproduce the issue? Please do let me know if there’s anything else I can provide. Right now, this is blocking our deployment pipeline as Azure DevOps fails the Testing stage (even though the tests themselves have passed).

Update - adding stack trace I did also manage to get a stack trace, by setting NODE_OPTIONS=--trace-warnings:

(node:10260) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 preprocessor:close listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
    at _addListener (events.js:390:17)
    at EventEmitter.addListener (events.js:406:10)
    at Object.wrap (C:\Users\dave.clarke\AppData\Local\Cypress\Cache\6.5.0\Cypress\resources\app\packages\server\lib\plugins\child\preprocessor.js:19:9)
    at execute (C:\Users\dave.clarke\AppData\Local\Cypress\Cache\6.5.0\Cypress\resources\app\packages\server\lib\plugins\child\run_plugins.js:119:27)    at EventEmitter.<anonymous> (C:\Users\dave.clarke\AppData\Local\Cypress\Cache\6.5.0\Cypress\resources\app\packages\server\lib\plugins\child\run_plugins.js:202:5)
    at EventEmitter.emit (events.js:315:20)
    at process.<anonymous> (C:\Users\dave.clarke\AppData\Local\Cypress\Cache\6.5.0\Cypress\resources\app\packages\server\lib\plugins\util.js:19:22)  
    at process.emit (events.js:315:20)
    at process.emit (C:\Users\dave.clarke\AppData\Local\Cypress\Cache\6.5.0\Cypress\resources\app\packages\server\node_modules\source-map-support\source-map-support.js:495:21)
    at emit (internal/child_process.js:876:12)
    at processTicksAndRejections (internal/process/task_queues.js:85:21)

Our team is also affected by this issue now with Cypress 6.3.0

Faced this also with latest release (6.0.0).

We are also seeing this on the 11th test…

The event emitter warnings are likely nothing important - these are node event bindings which don’t affect running tests in the browser. We’ve had memory issues in the past but it always been related to the browser - the node process itself never uses up that much memory.

This is something we likely need to look at and increase the number of listeners.

Regardless - you are definitely getting OOM’s so something has to be wrong. The thing is though - Cypress runs literally thousands of projects, many of which have many more specs than that - sometimes hundreds of spec files. Cypress also records millions of test runs on a regular basis. I’m saying that because this issue could not possibly be as simple as adding 8 spec files with no content. If that were the case, the thousands of internal tests we run on Cypress would all crash immediately.

There has to be something unique to your system that’s causing this. How much memory does your system actually have? You say that your OS is both linux and mac - have you seen this exact crash on two independent systems? Your last screenshot looks different as if it’s from a CI provider.

Still existing in 6.8.0.

I’m seeing the same error message using Cypress 5.6.0 running locally or through AWS code-pipeline. Any idea on when will this get fixed? image

image

Again, I want to reiterate:

We are aware of the warnings being displayed for Possible EventEmitter memory leak detected. and believe this to not affecting the behavior or Cypress.

We do plan to fix this warning message.

If you are having a situation where the browser crashes, does not load, or in general effects your testing suite run performance (besides just printing this EventEmitter error!), please open a new issue detailing how to reproduce the error locally on our machines.

We will be locking this issue to reduce unrelated noise, as this is thoroughly documented and reproducible.

We’re also seeing the same error on 11th test

We are also using cypress-multi-reporters and cypress-multi-reporters. The memory leak issue is serious as it impedes stability, availability, and scalability. I don’t think we can get corporate approval for cypress dashboard service if the core framework has infra issues. Please help, thank you.

No change for me with 6.2.0, and we’ve been running headless Electron all along. The issue is still happening.

Cypress 6.5.0 and running the last test on 10th spec file produced aforementioned error. Browser used (chrome)

Running: **.test.ts (10 of 10) (node:21792) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 preprocessor:close listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit

Since moving to Cypress 6.x I have the same error that hangs completely most times on CI, never on dev laptop.

                                 
                                 Running:  00_quick/05_url_state_spec.js                                                 (10 of 15)
2021-01-20T04:38:39.699Z [WARNING]: (node:3742) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 preprocessor:close listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
2021-01-20T04:38:41.885Z [INFO]: 
2021-01-20T04:38:41.886Z [INFO]: 
2021-01-20T04:38:41.897Z [INFO]: 05 URL State:
2021-01-20T04:38:41.898Z [INFO]: select county
2021-01-20T04:38:52.972Z [INFO]: ✓ when unauthorized and load state (9323ms)
2021-01-20T04:38:53.125Z [INFO]: select polygon type
2021-01-20T04:39:02.401Z [INFO]: ✓ when unauthorized and load state (9184ms)
2021-01-20T04:39:02.573Z [INFO]: select polygon type and count stats
2021-01-20T04:39:14.352Z [INFO]: ✓ when unauthorized and load state (11936ms)

Hangs at same point every time after that message. Profiler shows:

2021-01-20T19:45:32.595Z [WARNING]: 2021-01-20T19:45:32.595Z cypress:server:util:process_profiler current & mean memory and CPU usage by process group:
                                    ┌─────────┬───────────────────┬──────────────┬──────────────────────────┬────────────┬────────────────┬──────────┬──────────────┬─────────────┐
                                    │ (index) │       group       │ processCount │           pids           │ cpuPercent │ meanCpuPercent │ memRssMb │ meanMemRssMb │ maxMemRssMb │
                                    ├─────────┼───────────────────┼──────────────┼──────────────────────────┼────────────┼────────────────┼──────────┼──────────────┼─────────────┤
                                    │    0    │    'Electron'     │      1       │          '4658'          │    1.19    │      1.22      │  799.39  │    643.94    │   1000.79   │
                                    │    1    │     'cypress'     │      1       │          '3608'          │   31.84    │     21.12      │  466.83  │    367.71    │     476     │
                                    │    2    │ 'electron-shared' │      4       │ '3610, 3762, 3611, 3804' │   24.58    │     15.49      │  241.96  │    227.8     │   269.41    │
                                    │    3    │     'plugin'      │      1       │          '3828'          │    1.15    │      1.12      │  194.99  │    196.2     │   198.11    │
                                    │    4    │     'ffmpeg'      │      1       │          '4657'          │    0.23    │      0.69      │  61.61   │    54.41     │    61.86    │
                                    │    5    │      'other'      │      2       │       '4688, 4689'       │     0      │       0        │   6.23   │     6.17     │    6.26     │
                                    │    6    │      'TOTAL'      │      10      │           '-'            │   58.99    │     39.26      │   1771   │   1384.41    │   1858.61   │
                                    └─────────┴───────────────────┴──────────────┴──────────────────────────┴────────────┴────────────────┴──────────┴──────────────┴─────────────┘
2021-01-20T19:46:32.698Z [WARNING]: 2021-01-20T19:46:32.697Z cypress:server:util:process_profiler current & mean memory and CPU usage by process group:
                                    ┌─────────┬───────────────────┬──────────────┬──────────────────────────┬────────────┬────────────────┬──────────┬──────────────┬─────────────┐
                                    │ (index) │       group       │ processCount │           pids           │ cpuPercent │ meanCpuPercent │ memRssMb │ meanMemRssMb │ maxMemRssMb │
                                    ├─────────┼───────────────────┼──────────────┼──────────────────────────┼────────────┼────────────────┼──────────┼──────────────┼─────────────┤
                                    │    0    │    'Electron'     │      1       │          '4658'          │   34.64    │      5.39      │  691.06  │    649.83    │   1000.79   │
                                    │    1    │     'cypress'     │      1       │          '3608'          │   21.83    │      21.2      │  466.72  │    378.72    │     476     │
                                    │    2    │ 'electron-shared' │      4       │ '3610, 3762, 3611, 3804' │    3.22    │     14.13      │  241.79  │    229.36    │   269.41    │
                                    │    3    │     'plugin'      │      1       │          '3828'          │     0      │      0.98      │  194.99  │    196.05    │   198.11    │
                                    │    4    │     'ffmpeg'      │      1       │          '4657'          │    2.54    │      0.92      │  61.88   │    55.34     │    61.88    │
                                    │    5    │      'other'      │      2       │       '4728, 4729'       │     0      │       0        │   6.22   │     6.17     │    6.26     │
                                    │    6    │      'TOTAL'      │      10      │           '-'            │   62.24    │     41.81      │ 1662.66  │   1415.32    │   1858.61   │
                                    └─────────┴───────────────────┴──────────────┴──────────────────────────┴────────────┴────────────────┴──────────┴──────────────┴─────────────┘
2021-01-20T19:47:32.823Z [WARNING]: 2021-01-20T19:47:32.822Z cypress:server:util:process_profiler current & mean memory and CPU usage by process group:
                                    ┌─────────┬───────────────────┬──────────────┬──────────────────────────┬────────────┬────────────────┬──────────┬──────────────┬─────────────┐
                                    │ (index) │       group       │ processCount │           pids           │ cpuPercent │ meanCpuPercent │ memRssMb │ meanMemRssMb │ maxMemRssMb │
                                    ├─────────┼───────────────────┼──────────────┼──────────────────────────┼────────────┼────────────────┼──────────┼──────────────┼─────────────┤
                                    │    0    │    'Electron'     │      1       │          '4658'          │   34.33    │      8.61      │  632.7   │    647.93    │   1000.79   │
                                    │    1    │     'cypress'     │      1       │          '3608'          │   21.81    │     21.26      │  463.19  │    387.16    │     476     │
                                    │    2    │ 'electron-shared' │      4       │ '3610, 3762, 3611, 3804' │    3.2     │     13.04      │  241.79  │    230.6     │   269.41    │
                                    │    3    │     'plugin'      │      1       │          '3828'          │     0      │      0.87      │  194.99  │    195.93    │   198.11    │
                                    │    4    │     'ffmpeg'      │      1       │          '4657'          │    2.11    │      1.06      │  61.88   │    56.07     │    61.88    │
                                    │    5    │      'other'      │      2       │       '4768, 4769'       │     0      │       0        │   6.03   │     6.16     │    6.26     │
                                    │    6    │      'TOTAL'      │      10      │           '-'            │   61.46    │     43.78      │ 1600.58  │   1433.85    │   1858.61   │
                                    └─────────┴───────────────────┴──────────────┴──────────────────────────┴────────────┴────────────────┴──────────┴──────────────┴─────────────┘
2021-01-20T19:48:32.919Z [WARNING]: 2021-01-20T19:48:32.919Z cypress:server:util:process_profiler current & mean memory and CPU usage by process group:
                                    ┌─────────┬───────────────────┬──────────────┬──────────────────────────┬────────────┬────────────────┬──────────┬──────────────┬─────────────┐
                                    │ (index) │       group       │ processCount │           pids           │ cpuPercent │ meanCpuPercent │ memRssMb │ meanMemRssMb │ maxMemRssMb │
                                    ├─────────┼───────────────────┼──────────────┼──────────────────────────┼────────────┼────────────────┼──────────┼──────────────┼─────────────┤
                                    │    0    │    'Electron'     │      1       │          '4658'          │   34.46    │     11.19      │  634.08  │    646.54    │   1000.79   │
                                    │    1    │     'cypress'     │      1       │          '3608'          │   21.78    │      21.3      │  462.64  │    394.02    │     476     │
                                    │    2    │ 'electron-shared' │      4       │ '3610, 3762, 3611, 3804' │    3.2     │     12.14      │  241.79  │    231.62    │   269.41    │
                                    │    3    │     'plugin'      │      1       │          '3828'          │     0      │      0.79      │  194.99  │    195.84    │   198.11    │
                                    │    4    │     'ffmpeg'      │      1       │          '4657'          │    2.48    │      1.2       │  61.88   │    56.65     │    61.88    │
                                    │    5    │      'other'      │      2       │       '4808, 4809'       │     0      │       0        │   6.14   │     6.16     │    6.26     │
                                    │    6    │      'TOTAL'      │      10      │           '-'            │   61.93    │     45.43      │ 1601.52  │   1449.09    │   1858.61   │
                                    └─────────┴───────────────────┴──────────────┴──────────────────────────┴────────────┴────────────────┴──────────┴──────────────┴─────────────┘
2021-01-20T19:49:33.027Z [WARNING]: 2021-01-20T19:49:33.027Z cypress:server:util:process_profiler current & mean memory and CPU usage by process group:
                                    ┌─────────┬───────────────────┬──────────────┬──────────────────────────┬────────────┬────────────────┬──────────┬──────────────┬─────────────┐
                                    │ (index) │       group       │ processCount │           pids           │ cpuPercent │ meanCpuPercent │ memRssMb │ meanMemRssMb │ maxMemRssMb │
                                    ├─────────┼───────────────────┼──────────────┼──────────────────────────┼────────────┼────────────────┼──────────┼──────────────┼─────────────┤
                                    │    0    │    'Electron'     │      1       │          '4658'          │   34.36    │      13.3      │  883.84  │    668.12    │   1000.79   │
                                    │    1    │     'cypress'     │      1       │          '3608'          │   22.11    │     21.37      │  461.43  │    399.64    │     476     │
                                    │    2    │ 'electron-shared' │      4       │ '3610, 3762, 3611, 3804' │    3.18    │      11.4      │  241.79  │    232.47    │   269.41    │
                                    │    3    │     'plugin'      │      1       │          '3828'          │     0      │      0.72      │  194.99  │    195.76    │   198.11    │
                                    │    4    │     'ffmpeg'      │      1       │          '4657'          │     0      │      1.09      │  61.88   │    57.12     │    61.88    │
                                    │    5    │      'other'      │      2       │       '4849, 4850'       │     0      │       0        │   6.13   │     6.15     │    6.26     │
                                    │    6    │      'TOTAL'      │      10      │           '-'            │   59.65    │     46.61      │ 1850.05  │   1482.51    │   1858.61   │
                                    └─────────┴───────────────────┴──────────────┴──────────────────────────┴────────────┴────────────────┴──────────┴──────────────┴─────────────┘
2021-01-20T19:50:33.182Z [WARNING]: 2021-01-20T19:50:33.181Z cypress:server:util:process_profiler current & mean memory and CPU usage by process group:
                                    ┌─────────┬───────────────────┬──────────────┬──────────────────────────┬────────────┬────────────────┬──────────┬──────────────┬─────────────┐
                                    │ (index) │       group       │ processCount │           pids           │ cpuPercent │ meanCpuPercent │ memRssMb │ meanMemRssMb │ maxMemRssMb │
                                    ├─────────┼───────────────────┼──────────────┼──────────────────────────┼────────────┼────────────────┼──────────┼──────────────┼─────────────┤
                                    │    0    │    'Electron'     │      1       │          '4658'          │   34.54    │     15.07      │  845.48  │    682.9     │   1000.79   │
                                    │    1    │     'cypress'     │      1       │          '3608'          │   21.91    │     21.41      │  461.97  │    404.44    │     476     │
                                    │    2    │ 'electron-shared' │      4       │ '3610, 3762, 3611, 3804' │    3.22    │     10.77      │  241.79  │    233.18    │   269.41    │
                                    │    3    │     'plugin'      │      1       │          '3828'          │     0      │      0.66      │  194.99  │    195.69    │   198.11    │
                                    │    4    │     'ffmpeg'      │      1       │          '4657'          │    1.03    │      1.08      │  61.88   │    57.52     │    61.88    │
                                    │    5    │      'other'      │      2       │       '4889, 4890'       │     0      │       0        │   6.2    │     6.16     │    6.26     │
                                    │    6    │      'TOTAL'      │      10      │           '-'            │    60.7    │      47.7      │ 1812.31  │   1507.87    │   1858.61   │
                                    └─────────┴───────────────────┴──────────────┴──────────────────────────┴────────────┴────────────────┴──────────┴──────────────┴─────────────┘
2021-01-20T19:51:33.277Z [WARNING]: 2021-01-20T19:51:33.277Z cypress:server:util:process_profiler current & mean memory and CPU usage by process group:
                                    ┌─────────┬───────────────────┬──────────────┬──────────────────────────┬────────────┬────────────────┬──────────┬──────────────┬─────────────┐
                                    │ (index) │       group       │ processCount │           pids           │ cpuPercent │ meanCpuPercent │ memRssMb │ meanMemRssMb │ maxMemRssMb │
                                    ├─────────┼───────────────────┼──────────────┼──────────────────────────┼────────────┼────────────────┼──────────┼──────────────┼─────────────┤
                                    │    0    │    'Electron'     │      1       │          '4658'          │   34.62    │     16.57      │  787.68  │    690.96    │   1000.79   │
                                    │    1    │     'cypress'     │      1       │          '3608'          │   21.75    │     21.44      │  461.79  │    408.53    │     476     │
                                    │    2    │ 'electron-shared' │      4       │ '3610, 3762, 3611, 3804' │    3.3     │     10.23      │  241.79  │    233.8     │   269.41    │
                                    │    3    │     'plugin'      │      1       │          '3828'          │     0      │      0.61      │  194.99  │    195.64    │   198.11    │
                                    │    4    │     'ffmpeg'      │      1       │          '4657'          │    4.03    │      1.31      │  61.88   │    57.86     │    61.88    │
                                    │    5    │      'other'      │      2       │       '4929, 4930'       │     0      │       0        │   6.22   │     6.16     │    6.26     │
                                    │    6    │      'TOTAL'      │      10      │           '-'            │   63.69    │     48.84      │ 1754.34  │   1525.48    │   1858.61   │
                                    └─────────┴───────────────────┴──────────────┴──────────────────────────┴────────────┴────────────────┴──────────┴──────────────┴─────────────┘
2021-01-20T19:52:33.398Z [WARNING]: 2021-01-20T19:52:33.398Z cypress:server:util:process_profiler current & mean memory and CPU usage by process group:
                                    ┌─────────┬───────────────────┬──────────────┬──────────────────────────┬────────────┬────────────────┬──────────┬──────────────┬─────────────┐
                                    │ (index) │       group       │ processCount │           pids           │ cpuPercent │ meanCpuPercent │ memRssMb │ meanMemRssMb │ maxMemRssMb │
                                    ├─────────┼───────────────────┼──────────────┼──────────────────────────┼────────────┼────────────────┼──────────┼──────────────┼─────────────┤
                                    │    0    │    'Electron'     │      1       │          '4658'          │   34.64    │     17.86      │  743.29  │    694.69    │   1000.79   │
                                    │    1    │     'cypress'     │      1       │          '3608'          │   21.91    │     21.47      │  462.57  │    412.14    │     476     │
                                    │    2    │ 'electron-shared' │      4       │ '3610, 3762, 3611, 3804' │    3.23    │      9.77      │  241.79  │    234.33    │   269.41    │
                                    │    3    │     'plugin'      │      1       │          '3828'          │     0      │      0.56      │  194.99  │    195.59    │   198.11    │
                                    │    4    │     'ffmpeg'      │      1       │          '4657'          │    1.45    │      1.32      │  61.88   │    58.14     │    61.88    │
                                    │    5    │      'other'      │      2       │       '4969, 4970'       │     0      │       0        │   6.18   │     6.16     │    6.26     │
                                    │    6    │      'TOTAL'      │      10      │           '-'            │   61.24    │     49.67      │  1710.7  │   1537.83    │   1858.61   │
                                    └─────────┴───────────────────┴──────────────┴──────────────────────────┴────────────┴────────────────┴──────────┴──────────────┴─────────────┘ 

It’s unclear why the Cypress devs insist that it doesn’t affect tests — it significantly increases run time when it occurs, and often causes failure by timeout. Locally for me it takes much longer but eventually passes, — yet fails on our TeamCity server, which makes the tests unusable.

This didn’t happen before v6, but occurs steadily in 6.0.0, 6.0.1, 6.1.0.

Unfortunately the ‘MaxListenersExceededWarning’ reappeared in cypress 5.5.0 (Windows 10 Azure pipeline), To make matters worse, Azure seems to have a bug that prevents ignoring or suppressing warnings. So the warning causes the Azure job to halt. I had to revert to a previous cypress version (5.3.0)

2020-11-02T14:29:12.6231102Z                                                                                                     
2020-11-02T14:29:12.6232683Z   Running:  04bladen\01blad-aanmaken-aanvullen.spec.js                                    (10 of 32)
2020-11-02T14:53:03.6976049Z npm : (node:7672) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 preprocessor:close 
2020-11-02T14:53:03.6976997Z listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
2020-11-02T14:53:03.6977242Z At D:\releaseagents\agent1\_work\_temp\50c5ee6a-6561-4459-b2c6-3f1bea42cece.ps1:27 char:1
2020-11-02T14:53:03.6977386Z + npm run e2e-cicd-tst-edge
2020-11-02T14:53:03.6977774Z + ~~~~~~~~~~~~~~~~~~~~~~~~~
2020-11-02T14:53:03.6978391Z     + CategoryInfo          : NotSpecified: ((node:7672) Max... increase limit:String) [], RemoteException
2020-11-02T14:53:03.6979208Z     + FullyQualifiedErrorId : NativeCommandError
2020-11-02T14:53:03.6979867Z  
2020-11-02T14:53:03.7861295Z ##[error]PowerShell exited with code '1'.

Nice to see more people get involved in tracking this down! Just a note that 11 files is not necessarily the root cause. We currently only have 9 test files, and it still happens on 6.5.0, in one of the files in the middle.

What I did for now is skip the tests where the issue happens, and only re-run them manually every couple of weeks or so. This way TeamCity can do daily tests without constant failures.

@brian-mann @jennifer-shehane @bahmutov

I believe this particular error is caused by reporting feature. I was able to solve this issue by not using mocha-junit-reporter and cypress-multi-reporters at the same time. Also able to solve this issue when used cucumber reporting by using *.js file for report generating when running multiple feature files.

In short, I believe the Cypress team (@jennifer-shehane ) needs to look at reporting feature-capability used at cypress.json. Somewhere it’s causing memory leakage to capture reporting stats for a test run. It can be either a Cypress or a particular reporter issue that integrates with cypress to get test script stats.

We’ve also encountered this issue besides random runs that hang forever on Bamboo. We should track this down and fix it properly.

Observed same issue in 6.0.1 version as well. Unable to run more than 7 spec files at once in Azure DevOps

We are facing the same issue on Azure VMs today with the version 4.4.0

Just saw this message in v3.3.1.

Same error with me while using Jenkins, any update for fix?

Also seeing this issue in Cypress 6.0.1.

We run 6 instances of cypress using a custom script (cannot show you the script or any of out tests, there are a lot of them and they are randomized in order, so it’s not related to a particular command from what it seems). Prior to 6.0.0, we never had this issue. Now we end up hitting it after 3 instances. There seems to be more memory leaks that came with the most recent release.

We are facing the same issue on Azure VMs. When there is a test failure, cypress hangs indefinitely. We started having this problem after upgrading cypress from 4.3.0 to 4.4.1

Added Ten test files (maxtest.spec1.js - maxtest.spec10.js) with:

describe(‘Emitter Test’, () => { it(‘Does not do much!’, () => { expect(true).to.equal(true) }) })

Running: aaMaxEmitterTest\maxtest.spec10.js (10 of 45) (node:47340) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 preprocessor:close listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit

Cypress 6.5.0 Node v12.2.0

@rnovosad still no luck, maybe I have not set it right?

cypress/support/index.js

import "./commands";

import "@cypress/code-coverage/support";

require("cypress-plugin-tab");

Cypress.setMaxListeners(40);

Cypress.on("window:before:load", function (win) {
	const original = win.EventTarget.prototype.addEventListener;
	win.EventTarget.prototype.addEventListener = function () {
		if (arguments && arguments[0] === "beforeunload") {
			return;
		}
		return original.apply(this, arguments);
	};
	Object.defineProperty(win, "onbeforeunload", {
		get: function () {},
		set: function () {},
	});
});

Update - Removed the below form the cypress/support/index.js no change:

Cypress.on("window:before:load", function (win) {
	const original = win.EventTarget.prototype.addEventListener;
	win.EventTarget.prototype.addEventListener = function () {
		if (arguments && arguments[0] === "beforeunload") {
			return;
		}
		return original.apply(this, arguments);
	};
	Object.defineProperty(win, "onbeforeunload", {
		get: function () {},
		set: function () {},
	});
});
Running:  goals\goal.spec.js                                                            (11 of 33)
(node:31516) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 will-download listeners added to [Session]. Use emitter.setMaxListeners() to increase limit

Still happening with 6.4.0. Also, we do use mocha-teamcity-reporter, so @guptapranay may be onto something. But without a reporter there won’t be any reason to run the tests, so we can’t easily drop it.

@brian-mann Any real updates on this?

This is causing significant delays in running cypress tests headless mode. Just got feedback to move back to Selenium to move away from this memory leak and delay execution issue.

I’m seeing the same message related to MaxListenersExceededWarning using Cypress 5.5.0 on Azure pipeline. However in my case it is not raising the same log above and the test is running fine after the message.

node:688) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 preprocessor:close listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit

==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.177.3
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================

./node_modules/.bin/cypress run --browser chrome --headless --config-file=./cypress.uat.json

  "devDependencies": {
    "cypress": "^5.5.0",
    "cypress-cucumber-preprocessor": "^1.19.0",
    "cypress-file-upload": "^3.5.3",
    "cypress-waitfor": "^1.1.0",
    "cypress-xpath": "^1.4.0",
  },

If you need some additional information from the logs, I can provide, please let me know. Thanks.

Retries plugin: https://github.com/Bkucera/cypress-plugin-retries Many plugins can be found here in the future: https://docs.cypress.io/plugins/

For us, as a workaround, the ‘retries’ plugin is helping. Tests do continue with this plugin

I am also having the same issue and numTestsKeptInMemory=1 also does not work.