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 7: A global uncaughtException handle is leaked for every completed test runner #4144

Closed
weswigham opened this issue Jan 7, 2020 · 1 comment · Fixed by #4147
Closed
Assignees
Labels
type: bug a defect, confirmed by a maintainer

Comments

@weswigham
Copy link

weswigham commented Jan 7, 2020

Description

A global uncaughtException handle is leaked for every completed test runner, in turn causing a MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 uncaughtException listeners added to [process]. Use emitter.setMaxListeners() to increase limit warning to be thrown by node.

Since every handler attached is identical in content here, attaching one for the first completed runner should be just as correct (although, functionality-wise, it may need to be detcahced once a new runner has started - it's unclear how the sequencing between multiple runners is intended to work out for this handler).

Steps to Reproduce

const mocha = require("mocha");
for (let i = 0; i < 15; i++) {
    const r = new mocha.Runner(new mocha.Suite(""+i, undefined));
    r.run();
}

Expected behavior:
No warnings from node.

Actual behavior:

A MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 uncaughtException listeners added to [process]. Use emitter.setMaxListeners() to increase limit warning is printed.

Reproduces how often:
Every time. You can paste that example code into a repl.

@juergba juergba added type: bug a defect, confirmed by a maintainer and removed unconfirmed-bug labels Jan 7, 2020
@juergba juergba self-assigned this Jan 7, 2020
@juergba
Copy link
Contributor

juergba commented Jan 11, 2020

@weswigham thanks for reporting and testing!

weswigham added a commit to weswigham/mocha that referenced this issue Jun 10, 2020
And only attach it initially within `start`. Since `self.uncaught` is a bound function, "removing" it immediately before adding it only prevents the same instance from leaking multiple handles - it still allows multiple runners to leak handles forever, even when those runners are ended (resulting in an issue akin to mochajs#4144).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants