Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 connection listeners added. Use emitter.setMaxListeners() to increase limit #1051

Closed
slim-hmidi opened this issue Jan 2, 2018 · 6 comments

Comments

@slim-hmidi
Copy link

  • Node.js Version: v8.4.0
  • OS: ubuntu 17.04

I run this test in jest:

test('run tests in parallel', () => {
  return Promise.all(_.range(3000).map((i) => {
    return Model.query().insert({ name: `user${i}` });
  }));
}, 60000);

I got this error:

(node:14910) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 connection listeners added. Use emitter.setMaxListeners() to increase limit
@bnoordhuis
Copy link
Member

node --trace-warning app.js makes it print a stack trace, that should tell you where the issue comes from. It might be benign, it might not be.

If it's benign, you can suppress it with ee.setMaxListeners(n).

@NickNaso
Copy link
Member

NickNaso commented Jan 2, 2018

@slim-hmidi Node.js as default allow you to set 10 listeners for any single event as reported here:
https://nodejs.org/dist/latest-v8.x/docs/api/events.html#events_eventemitter_defaultmaxlisteners
If you want change this behavior you as @bnoordhuis wrote in the previous thread you need to use the method setMaxListeners as reported here:
https://nodejs.org/dist/latest-v8.x/docs/api/events.html#events_emitter_setmaxlisteners_n
Remember if you increase indiscriminately the number of maximum listener for any single event you could experiment some performance issue.
Hope to be helpful

@jennyvallon
Copy link

jennyvallon commented Mar 12, 2018

@bnoordhuis it's --trace-warnings app.js
the s is missing

@nimatrazmjo
Copy link

@jennyvallon, awesome thank you.

@rogeriojlle
Copy link

Is it possible to identify in "Model" when the query ends and remove the listener?
Maybe this helps, causing setMaxListeners (#) to have a smaller number or even need to set it?

Like that?

const {createServer} = require ('http');
const ffmpeg = ... \\ a EventEmitter
const server = createServer ((req, res) => {

    let bufEvt = (d) => {
      res.write (d);
    }
    ...
    ...

    case '/filme.mp4':

       res.writeHead (200, {
         'Content-Type': 'video / mp4',
         'Transfer-Encoding': 'chunked'
       });

       ffmpeg.on ('buf', bufEvt);

       req.on ('close', (c) => {
         ffmpeg.removeListener ('buf', bufEvt);
       });

       req.on ('abort', (c) => {
         ffmpeg.removeListener ('buf', bufEvt);
       });

     break;
    ...
    ...
  )};

@alfasin
Copy link

alfasin commented Oct 21, 2024

I tried a few different solutions that didn't work for me:

  • increasing --max-old-space-size
  • using the node flag: node --no-compilation-cache
  • use --runInBand
  • use --expose-gc
  • limiting the number of workers

What did work for me:

Limiting the idle memory per worker (setting: workerIdleMemoryLimit).

I'm also limiting the number of workers so maybe it was a combination of the solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants