Skip to content

MaxListenersExceededWarning for 'error' and 'ready' listeners #102

@dylanjha

Description

@dylanjha

When creating 11 producer queues with the following configuration I'm seeing the MaxListenersExceededWarning in node 8.9.1.

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

These queues are only meant to be producer queues, to push new jobs into the queue, not worker queues, so the overhead should be minimized.

I think this happens because of two things:

  1. the Queue class is a subclass of Emitter https://github.com/bee-queue/bee-queue/blob/master/lib/queue.js#L13
  2. somewhere in the Queue instantiation process bee-queue is attaching event handlers to the 'ready' and 'error' events.

Things I can't figure out:

  1. Where is number 2 happening?
  2. Is Queue correctly removing event handlers when necessary
  3. Is this a warning that is expected to show up?

It seems reasonable that on a webserver a user of bee-queue would want to instantiate > 10 producer queues. In this reasonable usage of the library I would not expect to get a node warning.

const Redis = require('redis')
const Queue = require('bee-queue')
const redis = Redis.createClient('redis://localhost:6379')

const sharedConfig = {
  redis,
  getEvents: false,
  isWorker: false
}

const queueNames = ['queue-1', 'queue-2', 'queue-3',  'queue-4', 'queue-5', 'queue-6', 'queue-7', 'queque-8', 'queue-9', 'queue-10', 'queue-11']
queueNames.forEach((queueName) => {
   const queue = new Queue(queueName, sharedConfig)
   console.log('queue created', queue.name)
})

image 2018-03-14 at 11 00 33 am

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions