question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 job ttl exceeded listeners added. Use emitter.setMaxListeners() to increase limit

See original GitHub issue

I’m getting (node:38) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 job ttl exceeded listeners added. Use emitter.setMaxListeners() to increase limit

my Kue implementation:

const kue = require('kue')
const $raven = require('./Raven')
const $jobs = require('../config/jobs')

const queue = kue.createQueue({
    // supress job level events
    jobEvents: false,
    // config redis connection
    redis: {
        host: process.env.REDIS_HOST || '127.0.0.1',
        port: process.env.REDIS_PORT || 6379
    }
})

queue.on('error', function (err) {
    console.log('Kue error \n', err)
    $raven.captureException(err)
})

// register jobs
Object.keys($jobs).forEach(name => {
    queue.process(name, $jobs[name])
})

module.exports = queue

a job declaration example

    'supplier-notify-created': async function (job, done) {
        try {
            console.log('notifying supplier was created...')
            let { message } = job.data

            await $axios({
                method: 'POST',
                url: $api.crmSupplierWebhook(),
                data: {
                    message
                }
            })

            console.log('successfully notified supplier was created')

            done()
        } catch (err) {
            console.log('error notifying supplier created', err)
            $raven.captureException(err)
            done(err)
        }
    }

job registration

const supplierNotifyUpdated = function (req, res) {
    let { message, user, supplierUuid } = req.body

    if (!message || !user || !supplierUuid) {
        throw new BadRequestError('Missing Parameters')
    }

    $kue.create('supplier-notify-updated', { message, user, supplierUuid })
        .priority('critical')
        .attempts(3)
        .removeOnComplete(true)
        .save()

    console.log('created supplier update notification job')
    res.json('ok')
}

whole project here: https://github.com/AddToEvent/JobProcessor

Kue version: 0.11.6

I’m using docker images to launch my app

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

7reactions
arboleyacommented, Jun 30, 2018
const queue = kue.createQueue({ ... })

queue.setMaxListeners(1000) // <- golden method

queue.on('error', function (err) {
...
6reactions
rohit-gohricommented, Jul 27, 2018

Instead of blindly setting Max Listeners to 1000, you can do :

queue.setMaxListeners(queue.getMaxListeners() + 1);

whenever you add a processor to the queue.

If you are using Concurrency, Just add the concurrency value you are using instead of 1.

In your case, you can just do:

queue.setMaxListeners(queue.getMaxListeners() + Object.keys($jobs).length);

before the loop.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Possible EventEmitter memory leak detected. 11 message lis ...
11 message lis teners added. Use emitter.setMaxListeners() to increase limit. My codebase is huge and I facing this error sometimes I don't know ......
Read more >
Node.js sends warnings when you add too many listeners to ...
11 event listeners added. Use emitter.setMaxListeners() to increase limit. Interesting, Node.js sends a warning to stderr when you add more ...
Read more >
Understanding memory leaks in node.js part 2 - alxolr
(node:10031) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. Eleven event listeners added. Use emitter.setMaxListeners() to ...
Read more >
Possible EventEmitter memory leak detected. 11 done ...
(node:89210) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 done listeners added. Use emitter.setMaxListeners() ...
Read more >
OptimalBits/bull - Gitter
"(node:7608) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 21 error listeners added to [Redis]. Use emitter.setMaxListeners() to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found