Nightwatch: possible EventEmitter memory leak detected. 11 error listeners added

Created on 9 Apr 2015  Β·  23Comments  Β·  Source: nightwatchjs/nightwatch

If I write a test with 10 or more steps, I get this warning:

(node) warning: possible EventEmitter memory leak detected. 11 error listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at ClientManager.addListener (events.js:179:15)
    at {NPM_INSTALL_DIR}\node_modules\nightwatch\lib\runner\testcase.js:61:10
    at _fulfilled ({NPM_INSTALL_DIR}\node_modules\nightwatch\node_modules\q\q.js:794:54)
    at self.promiseDispatch.done ({NPM_INSTALL_DIR}\node_modules\nightwatch\node_modules\q\q.js:823:30)
    at Promise.promise.promiseDispatch ({NPM_INSTALL_DIR}\node_modules\nightwatch\node_modules\q\q.js:756:13)
    at {NPM_INSTALL_DIR}\node_modules\nightwatch\node_modules\q\q.js:516:49
    at flush ({NPM_INSTALL_DIR}\node_modules\nightwatch\node_modules\q\q.js:110:17)
    at process._tickCallback (node.js:355:11)

The warning makes sense, but it is annoying. So far, I've just had to keep my steps below 10 per test. Any other workarounds/solutions are welcome!

enhancement

Most helpful comment

@beatfactor This is happening again in 1.0.11

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

 win7chrome [Register Test] Test Suite 
 win7chrome ========================== 
 win7chrome Results for:  Register - Step 1 
 win7chrome βœ” Element <body> was present after 256 milliseconds. 
 win7chrome βœ” Element <#register_your_details_details_forename> was present after 110 milliseconds. 
 win7chrome βœ” Element <#register_your_details_details_surname> was present after 132 milliseconds. 
 win7chrome βœ” Element <#register_your_details_email> was present after 136 milliseconds. 
 win7chrome βœ” Element <#register_your_details_password> was present after 99 milliseconds. 
 win7chrome βœ” Element <#register_your_details_details_subscribe> was present after 167 milliseconds. 
 win7chrome βœ” Element <#register-step1-btn> was present after 115 milliseconds. 
 win7chrome βœ” Element <#register-step1-btn> was not present after 197 milliseconds. 
 win7chrome βœ” [Register Test] Register - Step 1 (18.023s) 
 win7chrome Results for:  Register - Step 2 
 win7chrome βœ” Element <body> was present after 124 milliseconds. 
 win7chrome βœ” Element <#register_your_role_roles_2> was present after 153 milliseconds. 
 win7chrome βœ” Element <#register_your_role_roles_6> was present after 133 milliseconds. 
 win7chrome βœ” Element <#register_your_role_otherRole> was present after 134 milliseconds. 
 win7chrome βœ” Element <#register-step2-btn> was present after 112 milliseconds. 
 win7chrome βœ” Element <#register-step2-btn> was not present after 217 milliseconds. 
 win7chrome βœ” [Register Test] Register - Step 2 (7.462s) 
 win7chrome Results for:  Register - Step 3 
 win7chrome βœ” Element <body> was present after 128 milliseconds. 
 win7chrome βœ” Element <#register_your_teaching_details_curriculum_3> was present after 124 milliseconds. 
 win7chrome βœ” Element <#register_your_teaching_details_curriculum_2> was present after 172 milliseconds. 
 win7chrome βœ” Element <#register_your_teaching_details_agesTaught > span:nth-child(1) > label> was present after 128 milliseconds. 
 win7chrome βœ” Element <#register_your_teaching_submit> was present after 140 milliseconds. 
 win7chrome βœ” Element <#register_your_teaching_submit> was not present after 234 milliseconds. 
 win7chrome βœ” [Register Test] Register - Step 3 (7.993s) 
 win7chrome Results for:  Register - Step 4 
 win7chrome βœ” Element <body> was present after 103 milliseconds. 
 win7chrome βœ” Element <#register_school_address_lookup_postcode> was present after 117 milliseconds. 
 win7chrome βœ” Element <#register_school_address_lookup_find> was present after 109 milliseconds. 
 win7chrome βœ” Element <.grey-message-box> was present after 272 milliseconds. 
 win7chrome βœ” Element <#manual-address-entry> was present after 140 milliseconds. 
 win7chrome βœ” Element <.grey-message-box> was not present after 216 milliseconds. 
 win7chrome βœ” Element <#skip-this-step> was present after 137 milliseconds. 
 win7chrome βœ” Element <#register_school_address_entry_submit> was not present after 148 milliseconds. 
 win7chrome βœ” [Register Test] Register - Step 4 (16.076s) 
 win7chrome Results for:  Register - Thank you 
 win7chrome βœ” Element <body> was present after 89 milliseconds. 
 win7chrome βœ” Element <#view-activities> was present after 113 milliseconds. 
 win7chrome βœ” Element <#view-activities> was not present after 92 milliseconds. 
 win7chrome βœ” Passed [equal]: My Activities - Explorify == My Activities - Explorify 
 win7chrome (node:5846) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 complete listeners added. Use emitter.setMaxListeners() to increase limit 
 win7chrome (node:5846) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added. Use emitter.setMaxListeners() to increase limit 
 win7chrome βœ” Element <.popup__welcome-btn--one> was present after 133 milliseconds. 
 win7chrome βœ– Timed out while waiting for element <.popup__welcome-btn--two> to be present for 500 milliseconds. - expected "found" but got: 1m"not found" 

This is running in Travis

All 23 comments

You can probably set it in the global beforeEach hook.

On Thu, Apr 9, 2015 at 12:57 PM, Adam SchΓΈnemann [email protected]
wrote:

If I write a test with 10 or more steps, I get this warning:

(node) warning: possible EventEmitter memory leak detected. 11 error listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at ClientManager.addListener (events.js:179:15)
at {NPM_INSTALL_DIR}\node_modules\nightwatch\lib\runner\testcase.js:61:10
at _fulfilled ({NPM_INSTALL_DIR}\node_modules\nightwatch\node_modules\q\q.js:794:54)
at self.promiseDispatch.done ({NPM_INSTALL_DIR}\node_modules\nightwatch\node_modules\q\q.js:823:30)
at Promise.promise.promiseDispatch ({NPM_INSTALL_DIR}\node_modules\nightwatch\node_modules\q\q.js:756:13)
at {NPM_INSTALL_DIR}\node_modules\nightwatch\node_modules\q\q.js:516:49
at flush ({NPM_INSTALL_DIR}\node_modules\nightwatch\node_modules\q\q.js:110:17)
at process._tickCallback (node.js:355:11)

The warning makes sense, but it is annoying. So far, I've just had to keep
my steps below 10 per test. Any other workarounds/solutions are welcome!

β€”
Reply to this email directly or view it on GitHub
https://github.com/beatfactor/nightwatch/issues/408.

It is not clear to me exactly how to do this... Would I not need to obtain a reference to the event emitter somewhere? I tried process.setMaxListeners but to not avail.
Thanks!

hi @beatfactor, in the global beforeEach hook what is the event emitter to setMaxListeners on? I have also set using process and 'this' to no avail...

You can also try:
https://nodejs.org/api/events.html#events_eventemitter_defaultmaxlisteners

On Thu, Apr 16, 2015 at 11:12 AM, dwest-ee [email protected] wrote:

hi @beatfactor https://github.com/beatfactor, in the global beforeEach
hook what is the event emitter to setMaxListeners on? I have also set using
process and 'this' to no avail...

β€”
Reply to this email directly or view it on GitHub
https://github.com/beatfactor/nightwatch/issues/408#issuecomment-93686918
.

hi, i have set it up in nightwatch/lib/index.js as
this.setMaxListeners(100);
and it does not work, even manually setting it in eventemitter2.js is not working.

Please suggest some solution. updated latest version of node 0.12 and still unresolved.

thank you

@beatfactor Setting EventEmitter.defaultMaxListeners works, but are you planning to address this in nightwatch? Feels like something the user of the library shouldn't have to do, given it was not necessary when using nightwatch v0.5.

Yes, but I think this was there all along.

On Friday, May 1, 2015, Jan K [email protected] wrote:

@beatfactor https://github.com/beatfactor Setting
EventEmitter.defaultMaxListeners works, but are you planning to address
this in nightwatch? Feels like something the user of the library shouldn't
have to do, given it was not necessary when using nightwatch v0.5.

β€”
Reply to this email directly or view it on GitHub
https://github.com/beatfactor/nightwatch/issues/408#issuecomment-98100396
.

@beatfactor where can I add this ? EventEmitter.defaultMaxListeners

I resolve this problem in nightwatch/lib/runner/testcase.js 35 line.

  this.startTime = new Date().getTime();
  this.results = null;
  this.errors = null;

  // FIXED erase a message of "possible EventEmitter memory leak detected..."
  this.suite.client.setMaxListeners(100);

  this.suite
    .beforeEach()
    .then(function() {

This has been added to 0.7.8.

@beatfactor This is happening again in 1.0.11

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

 win7chrome [Register Test] Test Suite 
 win7chrome ========================== 
 win7chrome Results for:  Register - Step 1 
 win7chrome βœ” Element <body> was present after 256 milliseconds. 
 win7chrome βœ” Element <#register_your_details_details_forename> was present after 110 milliseconds. 
 win7chrome βœ” Element <#register_your_details_details_surname> was present after 132 milliseconds. 
 win7chrome βœ” Element <#register_your_details_email> was present after 136 milliseconds. 
 win7chrome βœ” Element <#register_your_details_password> was present after 99 milliseconds. 
 win7chrome βœ” Element <#register_your_details_details_subscribe> was present after 167 milliseconds. 
 win7chrome βœ” Element <#register-step1-btn> was present after 115 milliseconds. 
 win7chrome βœ” Element <#register-step1-btn> was not present after 197 milliseconds. 
 win7chrome βœ” [Register Test] Register - Step 1 (18.023s) 
 win7chrome Results for:  Register - Step 2 
 win7chrome βœ” Element <body> was present after 124 milliseconds. 
 win7chrome βœ” Element <#register_your_role_roles_2> was present after 153 milliseconds. 
 win7chrome βœ” Element <#register_your_role_roles_6> was present after 133 milliseconds. 
 win7chrome βœ” Element <#register_your_role_otherRole> was present after 134 milliseconds. 
 win7chrome βœ” Element <#register-step2-btn> was present after 112 milliseconds. 
 win7chrome βœ” Element <#register-step2-btn> was not present after 217 milliseconds. 
 win7chrome βœ” [Register Test] Register - Step 2 (7.462s) 
 win7chrome Results for:  Register - Step 3 
 win7chrome βœ” Element <body> was present after 128 milliseconds. 
 win7chrome βœ” Element <#register_your_teaching_details_curriculum_3> was present after 124 milliseconds. 
 win7chrome βœ” Element <#register_your_teaching_details_curriculum_2> was present after 172 milliseconds. 
 win7chrome βœ” Element <#register_your_teaching_details_agesTaught > span:nth-child(1) > label> was present after 128 milliseconds. 
 win7chrome βœ” Element <#register_your_teaching_submit> was present after 140 milliseconds. 
 win7chrome βœ” Element <#register_your_teaching_submit> was not present after 234 milliseconds. 
 win7chrome βœ” [Register Test] Register - Step 3 (7.993s) 
 win7chrome Results for:  Register - Step 4 
 win7chrome βœ” Element <body> was present after 103 milliseconds. 
 win7chrome βœ” Element <#register_school_address_lookup_postcode> was present after 117 milliseconds. 
 win7chrome βœ” Element <#register_school_address_lookup_find> was present after 109 milliseconds. 
 win7chrome βœ” Element <.grey-message-box> was present after 272 milliseconds. 
 win7chrome βœ” Element <#manual-address-entry> was present after 140 milliseconds. 
 win7chrome βœ” Element <.grey-message-box> was not present after 216 milliseconds. 
 win7chrome βœ” Element <#skip-this-step> was present after 137 milliseconds. 
 win7chrome βœ” Element <#register_school_address_entry_submit> was not present after 148 milliseconds. 
 win7chrome βœ” [Register Test] Register - Step 4 (16.076s) 
 win7chrome Results for:  Register - Thank you 
 win7chrome βœ” Element <body> was present after 89 milliseconds. 
 win7chrome βœ” Element <#view-activities> was present after 113 milliseconds. 
 win7chrome βœ” Element <#view-activities> was not present after 92 milliseconds. 
 win7chrome βœ” Passed [equal]: My Activities - Explorify == My Activities - Explorify 
 win7chrome (node:5846) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 complete listeners added. Use emitter.setMaxListeners() to increase limit 
 win7chrome (node:5846) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added. Use emitter.setMaxListeners() to increase limit 
 win7chrome βœ” Element <.popup__welcome-btn--one> was present after 133 milliseconds. 
 win7chrome βœ– Timed out while waiting for element <.popup__welcome-btn--two> to be present for 500 milliseconds. - expected "found" but got: 1m"not found" 

This is running in Travis

Hi

Please reopen this issue.

I encountered the same issue with nightwatch 1.0.14

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

Best regards

Hi @beatfactor, could you reopen this?

Hi everybody, I have also encountered this warning message.

process.setMaxListeners(0)

Didn't helped, but I solved it in this way:

require('events').EventEmitter.defaultMaxListeners = 100;

durty, but at least it works

Also sees this problem, any updates?

As per @kschingiz Adding require('events').EventEmitter.defaultMaxListeners = 100; to the top of nightwatch.conf.js silenced the error for me too.

FWIW I identified a particular long running test that was causing this issue. I set the following in the test file to ensure that the usual limit on event listeners was preserved elsewhere:

...
const {EventEmitter} = require('events');

module.exports = {
  beforeEach: client => {
    // Increase max listeners for this long running test
    EventEmitter.defaultMaxListeners = 100;
    return ...;
  },
  ..., // Run long test
  afterEach: () => {
    // Reset max listeners to the node.js default once the test is complete.
    EventEmitter.defaultMaxListeners = 10;
  }
};

Working for me just as @mpvosseller said but honestly I don't like it, can you reopen the issue please @beatfactor

@beatfactor Also getting this issue on long-running tests or tests with many steps. Ideally wouldn't have to have to implement a hacky fix.

getting same issue in my test case as well. @beatfactor can you please suggest that where we have set the config to overcome this in night watch if resolved.

Getting the same issue when running long keyboard navigation tests

I am seeing the same error with long test

+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maxgalbu picture maxgalbu  Β·  3Comments

Zechtitus picture Zechtitus  Β·  4Comments

manjero picture manjero  Β·  4Comments

t00f picture t00f  Β·  3Comments

willli666 picture willli666  Β·  3Comments