possible EventEmitter memory leak detected

103 views
Skip to first unread message

dav...@jones03.co.uk

unread,
Jun 28, 2017, 5:17:32 AM6/28/17
to CasperJS, David Fleming
Hi,

I have been using CasperJS with PhantomJS for a number of weeks and everything was working as expected. However, I encountered a problem yesterday that took a lot of investigating before I could resolve the problem. I started receiving the following message after some more tests were added (added to the same file as other tests):

(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.

I spent a lot of time googling for information on the issue but kept getting results for the equivalent problem in node based applications. I could not find anything for CasperJS/PhantomJS. I eventually decided to look into the CasperJS source and managed to find where the message was being raised. It was coming from the events.js file in modules directory. After a bit more searching around the source I discovered that I could increase the max listeners by calling the setMaxListeners method on the casper prototype. This then resolved my problem. 

Just for reference, I pulled CasperJS and PhantomJS into my project from NPM and invoke casper from an NPM script. The mention of node in the console output along with this fact added more confusion because I wasn't sure if it was something to do with node (via NPM) or CasperJS/PhantomJS.

The point I would like to raise in here is that though the error message was correct, the suggestion was misleading and didn't help me to resolve the problem. This is how the error message presented itself in my console output:

(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit. 11
  <rest of path>/src/client/phantomjs:/platform/events.js:184 in addListener
FAIL (node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit. 11
Failed on url: http://localhost:8080/criminal/case-details
#    type: error
#    file: <rest of path>/src/client/test/e2e/dist/scenarios/test.scn.js
#    subject: false
#    error: "(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit. 11"
#    stack: in addListener() in phantomjs://platform/events.js:184

It tells the user to use emitter.setMaxListeners, but I was not able to determine how to do this. All attempts to search through google just showed how to do it in a node based application. The line starting with "stack" also confused me because I couldn't determine where the file was located, though this is probably down tomy lack of experience with PhantomJS.

I would like to propose two things and would welcome your thoughts. 
  1. Change the error message in modules/events.js to indicate that you can up the limit using casper.setMaxListeners.
  2. Update the online documentation to show that this method exists on the casper prototype and when/why it should be used.
I appreciate that upping this limit may be masking a problem, but it would be good to reference it in the documentation and explain the consequences of changing this value. I am happy to create a pull requests for both points if the community think it is the right thing to do.

dav...@jones03.co.uk

unread,
Jun 28, 2017, 5:37:41 AM6/28/17
to CasperJS, david.gera...@gmail.com
Just to add to my original post. I have since discovered what was the underlying cause of the error. I found out by modifying the error message in event.js to write out the type of listener it was trying to add. On seeing it I was quickly able to diagnose the problem.

I would like to amend point 1 in my original post to say that the error message should also indicate what type of listener it was attempting to add when the threshold was met. I think this would save others a lot of time if they encounter the same problem.

Ken

unread,
Jun 30, 2017, 7:42:08 AM6/30/17
to CasperJS, david.gera...@gmail.com
This is great sharing! Yes CasperJS is actually not a Node.js module, I believe it was distributed that way and not really meant to be foolproof with Node.js (maybe stemming from PhantomJS due to the nature - http://phantomjs.org/faq.html).

I thought what you raised is great and wanted to repost as an issue on your behalf but I don't know your GitHub user ID to tag you and keep you in the loop. Can you raise an issue here or let me know your ID? - https://github.com/casperjs/casperjs/issues Thanks!

dav...@jones03.co.uk

unread,
Jun 30, 2017, 10:47:18 AM6/30/17
to CasperJS, david.gera...@gmail.com
Thanks Ken

My Git ID is: djwales

David

Ken Soh

unread,
Jul 1, 2017, 7:21:39 AM7/1/17
to casp...@googlegroups.com, david.gera...@gmail.com
Thanks David! I've raised the issue, copying you and current CasperJS main maintainer - https://github.com/casperjs/casperjs/issues/1844

--
CasperJS homepage & documentation: http://casperjs.org/
CasperJS @github: https://github.com/n1k0/casperjs
 
You received this message because you are subscribed to the Google Groups "casperjs" group.
Visit this group at http://groups.google.com/group/casperjs?hl=en.
---
You received this message because you are subscribed to a topic in the Google Groups "CasperJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/casperjs/KSokCoogNp0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to casperjs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ken Soh

unread,
Jul 3, 2017, 2:40:19 AM7/3/17
to casp...@googlegroups.com, David Fleming
Hi David, CasperJS main maintainer Jef has replied to the thread. You can click on the subscribe button on that page to be alerted of updates and also let Jef know your thoughts :)

dav...@jones03.co.uk

unread,
Jul 4, 2017, 10:22:02 AM7/4/17
to CasperJS, david.gera...@gmail.com
Thanks Ken. I will take a look.

David
To unsubscribe from this group and all its topics, send an email to casperjs+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages