cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.68k stars 3.16k forks source link

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

Closed YevheniiaMazur closed 3 years ago

YevheniiaMazur commented 6 years ago

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:

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

brian-mann commented 6 years ago

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.

YevheniiaMazur commented 6 years ago

@brian-mann , I reproduced this issue both at MacOS and at Linux (at separate devices). Screenshot with JavaScript heap out of memory error was from Travis CI log. If it will be helpful, I can give you link to PR with this error at github, or try reproduce this issue at empty Angular project, and than give you link to it. Which option is better for you?

brian-mann commented 6 years ago

PR is fine since we can look at the code and should be able to repro

YevheniiaMazur commented 6 years ago

This is pr with JavaScript heap out of memory error: https://github.com/valor-software/ngx-bootstrap/pull/3701

And here pr, where I reproduced, that adding 8th spec (even if previous specs were all empty) started throwing warning about memory leak https://github.com/valor-software/ngx-bootstrap/pull/3742

YevheniiaMazur commented 6 years ago

For first PR to run e2e tests locally you have to follow next steps:

For second PR, you have to use next commands:

YevheniiaMazur commented 6 years ago

@brian-mann I've create empty angular project, install there cypress, and this issue appeared there too. link to project: https://github.com/YevheniiaMazur/emptyProjSypress How to run empty specs:

jennifer-shehane commented 6 years ago

This warning does display for me in the Angular empty specs run:

Warning: Possible EventEmitter memory leak detected. 11 close listeners added. 
Use emitter.setMaxListeners() to increase limit

There is no warning in Angular empty specs run for me about JavaScript heap out of memory

brian-mann commented 6 years ago

@YevheniiaMazur @jennifer-shehane I expect to see the node event emitter warning - we can take a look at that and get it fixed.

I do not expect to see OOM crashes - so anything that reproduces this is helpful. @YevheniiaMazur you mentioned that you were seeing this in Travis - do you mind setting up the empty specs project there and giving a link to a run where this has happened?

We'll try to look at the event emitter problem asap just to see where it's coming from and make sure it's not the root cause - preliminarily I don't think it is.

brian-mann commented 6 years ago

@YevheniiaMazur after looking at this more - I think you're really describing two separate issues here.

Issue 1. When Cypress loads in more than 8 spec files you see an event emitter warning in node. This should be fixed by us - but its incidental and not related to the OOM at all. This warning happens even if there is no content in the spec file.

Issue 2. This is the real OOM error - but it's only happening when you run all of your tests in the browser. Essentially this error is real and correct - the browser is exhausting all of the available memory in Travis and dying. Why this is happening is another story. This could very well be indicative of a memory leak in Cypress (in the browser).

Issue 2 likely has nothing to do with issue 1.

With that said - there are several existing issues already open in Cypress that have mentioned similar situations. Not OOM'ing - but Cypress slowing down over a period of time. We're aware of these and are about to land a version of Cypress that changes the way we run specs. Instead of bundling them all together - the default way will be to chunk them by spec file and in between that killing the renderer process (the browser). That will purge primed memory and help prevent OOM. This is landing soon (as in landing in Feb) and there's already an open branch with this work.

This is part of a much larger issue here which goes into all the glorious intricate details.

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

If your issue is related to this one then it'll be fixed relatively soon. For now you can manually run your specs in isolation with this comment. This will come close to working the same way as when we make this the default in a newer version.

https://github.com/cypress-io/cypress/issues/416#issuecomment-337400871

joelparkerhenderson commented 6 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:

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

Thank you.

drewbrend commented 6 years ago

I've also just run into this issue. It seems to be related to the number of specs for us as well. We have 12 specs in this project currently, they run well and that error is not seen in the console log.

I am working on a ticket now which adds 3 more specs to the run, we now consistently see this error on the 10th and 11th spec ran, then the build hangs and times out.

subpx commented 6 years ago

Having same issue. Start getting error after running 10 spec files.

drewbrend commented 6 years ago

Just wanted to add, I only see this in electron browser. Running in chrome does not have this issue. We've switched to chrome for now.

stclairdaniel commented 5 years ago

I'm having the same issue - it shows the error after the 10th spec file finishes.

fijimunkii commented 5 years ago

To address this issue simply change numTestsKeptInMemory down from 50 to something sane like 1 or 0 https://docs.cypress.io/guides/references/configuration.html#Global

haugsrud commented 5 years ago

Setting numTestsKeptInMemory=0 does not work for me. I have tried both with electron and chrome-browsers.

I still get the error after 10th spec file finishes.

Using Cypress v3.1.0

surfjedi commented 5 years ago

We are also seeing this on the 11th test..

Junaid-Aslam1 commented 5 years ago

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

JefferE commented 5 years ago

We are also seeing this on the 11th test..

benmardana commented 5 years ago

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

nikhilesh009 commented 5 years ago

We're also getting the same error, it's weird. is any temporary fix ? i am blocked ;( I ran the test and generated video, normal test (in test runner )run 1.30 second but when i ran on CI ,it hanged up

screenshot 2018-12-07 at 08 36 50

it keep loading until i stopped the test.

nrso commented 5 years ago

We are also having it after the 10th test

(node:4948) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exitEarlyWithErr listeners added. Use emitter.setMaxListeners() to increase limit
jennifer-shehane commented 5 years ago

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.

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

This issue will be left open for Cypress to address the EventEmitter memory leak and it's warning message only.

PetMou commented 5 years ago

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

christophechevalier commented 5 years ago

We're also seeing the same error on 10th & 11th test

Running: service.e2e-spec.ts... (10 of 15) (node:1183) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 preprocessor:close listeners added. Use emitter.setMaxListeners() to increase limit

Running: services.e2e-spec.ts... (11 of 15) (node:1008) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exitEarlyWithErr listeners added. Use emitter.setMaxListeners() to increase limit

Used Current Versions :

The first job failed because memory leak detected, but the second job passed without MaxListenersExceededWarning.

christophechevalier commented 5 years ago

@PetMou Hi !

Thanks.

jennifer-shehane commented 5 years ago

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

christophechevalier commented 5 years ago

@jennifer-shehane What's solution do you recommand ?

PetMou commented 5 years ago

We use the 'retries' plugin for other reasons (AUT issues). The 'MaxListenerExeededWarning' does show up, but does not seem to have any negative effect upon test outcome. The test run just carries on. Perhaps the size of each 'it' is of importance. Every 'it' starts with a fresh browser session

christophechevalier commented 5 years ago

Ok but now, every time I push on the CI, the first pipeline fail, and second succeed. Which means that when we rerun the tests, they pass. This seems to correct the problem ! image I found 3 errors recurring during the failed job :

  1. 
    Running: services.e2e-spec.ts...                                                       (11 of 15) 
    (node:1012) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exitEarlyWithErr listeners added. Use emitter.setMaxListeners() to increase limit
    
    Services
    ...
    1) should reset services search when changing page
    
    14 passing (4m)
    1 failing
    
    1) Services should reset services search when changing page:
     CypressError: Timed out retrying: Not enough elements found. Found '3', expected '8'.
      at Object.cypressErr (http://localhost:4200/__cypress/runner/cypress_runner.js:65283:11)
      at Object.throwErr (http://localhost:4200/__cypress/runner/cypress_runner.js:65248:18)
      at Object.throwErrByPath (http://localhost:4200/__cypress/runner/cypress_runner.js:65275:17)
      at retry (http://localhost:4200/__cypress/runner/cypress_runner.js:58816:16)
      at http://localhost:4200/__cypress/runner/cypress_runner.js:50924:18
      at tryCatcher (http://localhost:4200/__cypress/runner/cypress_runner.js:127195:23)
      at Promise._settlePromiseFromHandler (http://localhost:4200/__cypress/runner/cypress_runner.js:125213:31)
      at Promise._settlePromise (http://localhost:4200/__cypress/runner/cypress_runner.js:125270:18)
      at Promise._settlePromise0 (http://localhost:4200/__cypress/runner/cypress_runner.js:125315:10)
      at Promise._settlePromises (http://localhost:4200/__cypress/runner/cypress_runner.js:125390:18)
      at Async._drainQueue (http://localhost:4200/__cypress/runner/cypress_runner.js:122119:16)
      at Async._drainQueues (http://localhost:4200/__cypress/runner/cypress_runner.js:122129:10)
      at Async.drainQueues (http://localhost:4200/__cypress/runner/cypress_runner.js:122003:14)
    
    (Results)
    
    ┌─────────────────────────────────────┐
    │ Tests:        15                    │
    │ Passing:      14                    │
    │ Failing:      1                     │
    │ Pending:      0                     │
    │ Skipped:      0                     │
    │ Screenshots:  1                     │
    │ Video:        false                 │
    │ Duration:     3 minutes, 55 seconds │
    │ Spec Ran:     services.e2e-spec.ts  │
    └─────────────────────────────────────┘

2. `CypressError: Timed out after waiting '60000ms' for your remote page to load.`
3. `CypressError: Timed out after waiting '60000ms' for your remote page to load.`

I found an issue open for that https://github.com/cypress-io/cypress/issues/2938

@jennifer-shehane https://github.com/cypress-io/cypress/issues/2938#issuecomment-487014545
It is seemingly random. So when we rerun the tests, they pass.
Is this problem :

> Page occasionally does not load from cy.visit() #2938  

is related by

> After creating eight spec files with any commands inside them, JavaScript heap out of memory  

or the opposite ?  

Thanks.
xlenz commented 5 years ago

Same in 3.3.0

actuallyReallyAlex commented 5 years ago

Just saw this message in v3.3.1.

zerdos commented 5 years ago

Same. v3.3.1, node 12.3.1, inside docker-compose

diniz26 commented 5 years ago

Acabei de ver esta mensagem na v3.3.1.

Eu também

jennifer-shehane commented 5 years ago

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.

arunkumawat commented 4 years ago

Works fine on local dev machine. Fails when we are running cypress in azure pipeline, Came right after added more then 10 spec files.

Just adding logs and latest versions if this helps -

using NPM command - ng run cypress-run && npx nyc report --reporter=cobertura

Versions

"devDependencies": {
        "@briebug/cypress-schematic": "^3.3.0",
        "@cypress/code-coverage": "^3.7.4",
        "@cypress/webpack-preprocessor": "5.1.1",
        "cypress": "^4.5.0",
        "cypress-multi-reporters": "^1.2.4"
}

Error Logs

<--- Last few GCs --->

[4777:0x3c905b000]   424294 ms: Mark-sweep 2040.4 (2052.1) -> 2039.9 (2052.4) MB, 2905.5 / 0.0 ms  (average mu = 0.081, current mu = 0.003) allocation failure scavenge might not succeed
[4777:0x3c905b000]   426809 ms: Mark-sweep 2040.0 (2052.4) -> 2039.9 (2052.6) MB, 2513.0 / 0.0 ms  (average mu = 0.043, current mu = 0.001) allocation failure GC in old space requested

<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x55bb8d476b79]
    1: StubFrame [pc: 0x55bb8d40701a]
Security context: 0x1b3124459581 <JSObject>
    2: initializeTypeChecker(aka initializeTypeChecker) [0x2b519c5bce41] [/home/vsts/work/1/s/user/ClientApp/node_modules/typescript/lib/typescript.js:1] [bytecode=0x377164a5f669 offset=543](this=0x15c425640469 <undefined>)
    3: createTypeChecker [0x141c6e0db889] [/home/vsts/work/1/s/user/ClientApp/node_modules/typescr...

1) An uncaught error was detected outside of a test

  0 passing (607ms)
  1 failing

  1) An uncaught error was detected outside of a test:
     Error: The following error originated from your test code, not from Cypress.

  > Fetching resource at '/__cypress/tests?p=cypress/integration/ui/home.spec.ts' failed

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure.
      at XMLHttpRequest.xhr.onerror (http://localhost:4200/__cypress/runner/cypress_runner.js:159595:14)

The following error was thrown by a plugin. We stopped running your tests because a plugin crashed. Please check your plugins file (`/home/vsts/work/1/s/user/ClientApp/cypress/plugins/index.js`)

 Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
    at ChildProcess.target.send (internal/child_process.js:678:16)
    at Object.send (/home/vsts/.cache/Cypress/4.6.0/Cypress/resources/app/packages/server/lib/plugins/util.js:34:27)
    at EventEmitter.<anonymous> (/home/vsts/.cache/Cypress/4.6.0/Cypress/resources/app/packages/server/lib/plugins/preprocessor.js:66:18)
    at EventEmitter.emit (events.js:215:7)

tput: No value for $TERM and no -T specified
(node:4777) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 preprocessor:close listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
(node:4777) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 preprocessor:close listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
tput: No value for $TERM and no -T specified
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! user@2.2.0 ci-test: `ng run user:cypress-run && npx nyc report --reporter=cobertura`
npm ERR! Exit status 1
nishants commented 4 years ago

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

psergiovieira commented 4 years ago

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

theandrewlane commented 4 years ago

Same issue here in 4.1.0 - running Cypress in Docker Ubuntu 18.04 😢

rcowsill commented 3 years ago

It looks like the ...11 exitEarlyWithErr listeners added... variant of the warning message is fixed as of the v4.2.0 release :+1:

(see: https://github.com/cypress-io/cypress/commit/474b80a50f0a8e5e049384b6233ee5f7f3b8dc22)

PetMou commented 3 years ago

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'.
willcoliveira commented 3 years ago

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.

ghost commented 3 years ago

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

KalleVuorjoki commented 3 years ago

Faced this also with latest release (6.0.0).

Arturace commented 3 years ago

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.

nikkieta commented 3 years ago

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

msabramo commented 3 years ago

Also seeing this issue in Cypress 6.0.1.

MohmedEmad commented 3 years ago

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

NPC commented 3 years ago

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.

ariellephan commented 3 years ago

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