Bull: Possible memory leak if too many process

Created on 21 Apr 2017  路  20Comments  路  Source: OptimalBits/bull

node: v6.9.5
bull: ^3.0.0-alpha.1

for (const name of lodash.range(11)) {
  bull.process(name.toString(), function ({ data }) {
    console.log('here')
  })
}

It will throw this error
(node:83132) Warning: Possible EventEmitter memory leak detected. 11 resumed listeners added. Use emitter.setMaxListeners() to increase limit

Most helpful comment

It's a property, not a method.

const EventEmitter = require( "events" );  
EventEmitter.defaultMaxListeners = 20;

All 20 comments

yeah, I noticed myself, probably not a leak though, just that we use more listeners than the max setting. I will confirm it and increase the limit to avoid the warning in the future.

I'm seeing this too, although I'm seeing it for error and message listeners, which I assume is still the same or a similar problem.

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

are you seeing it in the latest alpha release as well?

@manast oh nice I didn't realize that that fix was in the alpha! I haven't tried 3.x yet because I wasn't sure what is changing, so I figured I'd play it safe until it's stable. (But no, this is from the non-alpha, so feel free to ignore!)

@manast I just noticed that warning message again in Bull 3.3.0:

(node:7572) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 global:completed listeners added. Use emitter.setMaxListeners() to increase limit
(node:7572) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 global:failed listeners added. Use emitter.setMaxListeners() to increase limit

Might be a completely different cause though.

cannot say without a code example

This is happening for me in v3.3.1 when I create more than 11 queues with this code:

function createQueue(name) {
  const queue = new Queue(name);

  queue.on('stalled', job => {
    console.log(`Job#${job.id} stalled, processing again.`);
  });
  return queue;
}

For example like this:

const createQueue = require('./create-queue.js');
const queues = [];

for (let i = 0; i < 20; i++) {
  queues.push(createQueue(`queue-${i}`));
}

Since I need to listen for stalled jobs, any ideas how to work around this?

@mxstbr just follow the hint you get from the warning :)

 MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 global:completed listeners added. Use emitter.setMaxListeners() to increase limit

Yeah but how do I get the emitter in the first place? Is that a global variable in Node?!

its global

Ohh that explains a lot, thanks @manast!

Getting "emitter is not defined" warnings. :confused:

const emitter = new EventEmitter();

But I don't have access to the instance bull uses, that's what I'm saying, so I can't do this:

bullEmitter.setMaxLIsteners()

EventEmitter.setDefaultMaxListeners()

Does not work in Node v6.11

EventEmitter.setDefaultMaxListeners()

sorry my bad, just use EventEmitter.defaultMaxListeners as explained in the URL above.

It's a property, not a method.

const EventEmitter = require( "events" );  
EventEmitter.defaultMaxListeners = 20;

thanks @manast

Oh that works, my bad. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PhillippOhlandt picture PhillippOhlandt  路  4Comments

ianstormtaylor picture ianstormtaylor  路  4Comments

NicolasDuran picture NicolasDuran  路  4Comments

btd picture btd  路  3Comments

joe-at-startupmedia picture joe-at-startupmedia  路  3Comments