EventEmitter memory leak detected


#1

Hi guys,

Lately I started getting console message saying:

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

In my start/events.js I have 17 listeners in total. Is this bad pratice? Should I lower amount of listeners and add more logic (switch case of event type or something) to fewer listeners?

Is this leak big problem? What should I do?

Thank you!


#2

@hlozancic Please share code, without having any code, it’s hard to answer any questions


#3

Hi Virk, sorry… Here is the code:

MY START/EVENTS.JS FILE:

const Event = use('Event')

Event.on('user::register', 'User.register')
Event.on('user::resendValidation', 'User.resendValidation')
Event.on('user::forgotPassword', 'User.forgotPassword')
Event.on('user::validated', 'User.validated')
Event.on('user::contactEmail', 'User.contactEmail')
Event.on('user::accountDeleteProcess', 'User.accountDeleteProcess')
Event.on('user::accountDeleted', 'User.accountDeleted')


// ELASTICSEARCH EVENTS
Event.on('elastic::create', 'Elastic.create')
Event.on('elastic::delete', 'Elastic.delete')

// GENERAL EVENTS
Event.on('general::contactUs', 'General.contactUs')

// TRACKING EVENTS
Event.on('track::visit', 'Track.visit')
Event.on('track::search', 'Track.search')

// LIKE EVENTS
Event.on('like::newLike', 'Like.newLike')
Event.on('like::unLike', 'Like.unLike')
Event.on('like::changeLike', 'Like.changeLike')

// FOLLOW EVENTS
Event.on('follow::newFollow', 'Follow.newFollow')
Event.on('follow::unFollow', 'Follow.unFollow')

I don’t belive you need code from my app/Listeners/ directory, in general it’s very simple actions depending on event for example it just sends email or adds some records to db.

For example, I could group all email based events to one listener… But I really liked this way :slight_smile:


#4

I don’t think this is the issue. Creating multiple events is fine, but having multiple listeners for a single event is problematic.

  1. Do you create any listeners inside your controllers?
  2. Also can you share, after taking what actions, this warning is raised?

#5
  1. Inside controllers I only use Event.fire(…) I have multiple different methods that can fire same listener (but I belive this is normal)

  2. Sadly, no… I spotted it inside log file. I will take more care and try to capture when it happens


#6

Yeah, coz defining multiple events is fine.


#7

It seams like node-apn module was wrongly implemented… It was not adonis memory leak issue :slight_smile: