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

Mocha test runner does not clean up uncaughtException listeners #4171

Closed
jehy opened this issue Jan 28, 2020 · 1 comment
Closed

Mocha test runner does not clean up uncaughtException listeners #4171

jehy opened this issue Jan 28, 2020 · 1 comment

Comments

@jehy
Copy link

jehy commented Jan 28, 2020

Prerequisites

  • [ x] Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • [ x] Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • [x ] 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • [x ] Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

When using mocha test runner, it does not remove uncaughtException listeners.
You can clearly see the issue in code line 919:
https://github.com/mochajs/mocha/blob/master/lib/runner.js

  this.on(constants.EVENT_RUN_END, function() {
    debug(constants.EVENT_RUN_END);
    process.removeListener('uncaughtException', uncaught);
    process.on('uncaughtException', self.uncaughtEnd);
    fn(self.failures);
  });

Listener is removed and then... Immedialtely another listener is added!
So if you use runner for running many tests, you will have all those listeners staying with you forever.
In my case, on project with 5000 tests I have a warning

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 501 uncaughtException listeners added to [process]. Use emitter.setMaxListeners() to increase limit

Steps to Reproduce

In description

Expected behavior:
I expect no listeners after runner ended,

Actual behavior:
Listeners stay.

Reproduces how often:
Always

Versions

mocha version 7.0.0

@jehy jehy changed the title Mocha test runner does not clean up Mocha test runner does not clean up uncaughtException listeners Jan 28, 2020
@jehy
Copy link
Author

jehy commented Jan 28, 2020

Sorry, fixed in 7.0.1 #4147

@jehy jehy closed this as completed Jan 28, 2020
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

1 participant