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/integrationfolder create 8 spec files with any content inside them it could be onlydescribe('', () => {}); - Run created tests using command: cypress run
Additional Info (images, stack traces, etc)
After adding 8th spec next warning appeared:

Even if there are no tests inside them

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

- 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
- fix: #1305 solve possible EventEmitter memory leak — committed to fritz-c/cypress by fritz-c 5 years ago
- Cypress issue https://github.com/cypress-io/cypress/issues/1305 — committed to socialsensingbot/frontend by neilellis 3 years ago
- Cypress issue https://github.com/cypress-io/cypress/issues/1305 — committed to socialsensingbot/frontend by neilellis 3 years ago
- duplicate test files to see the MaxEventListeners warning Ref: https://github.com/cypress-io/cypress/issues/1305 + disable video generation to speed up the test execution — committed to marc-rutkowski/cypress-example-reporters by marc-rutkowski 3 years ago
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:
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.
@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 emptycypress.jsonfile.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 limitAt 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:Our team is also affected by this issue now with Cypress
6.3.0Faced 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?
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.
Hangs at same point every time after that message. Profiler shows:
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)
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-reporterandcypress-multi-reportersat the same time. Also able to solve this issue when used cucumber reporting by using*.jsfile 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
Update - Removed the below form the cypress/support/index.js no change:
Still happening with
6.4.0. Also, we do usemocha-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./node_modules/.bin/cypress run --browser chrome --headless --config-file=./cypress.uat.jsonIf 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=1also does not work.