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
Move removal of uncaughtException
handler into end
callback
#4329
Conversation
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).
Thanks. Can you suggest (or even implement) a test case that will assert this doesn't leak (in your use case)? |
Looks like, at minimum, those failing tests need to be fixed (change |
The failing tests would seem to indicate that |
Anyways, I probably can't return to this for a bit (was kinda hoping the simple fix would work in CI like it did locally); it'd be best if someone else could help pick this up (ideally someone more familiar with mocha) now that I've made someone aware of the regression. You can see the listeners warning get triggered over in https://github.com/microsoft/TypeScript with a |
@weswigham It's We don't have any tests for instantiating multiple Please don't mind if I/we push to your branch. |
@mochajs/core To summarize: TypeScript consumes Mocha programmatically, and they instantiate multiple |
Technically, there's the one from #4147, but it doesn't seem to capture this issue, likely due to some reordering of when handlers are attached internally. |
@@ -1027,11 +1028,9 @@ Runner.prototype.run = function(fn, opts) { | |||
debug(constants.EVENT_RUN_END); | |||
debug('run(): emitted %s', constants.EVENT_RUN_END); | |||
fn(self.failures); | |||
self._removeEventListener(process, 'uncaughtException', self.uncaught); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the uncaught exception handler here is incorrect, too early, IMO. There can be exceptions bubbling up after runner's end. We even have a check for this (STATE_STOPPED
) in Runner#_uncaught
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a runner 'end'
s, then results are likely to have been reported based on that runner. If a test could error post-end, it's too late to include it in results... Simultaneously, if a test still has outstanding actions like that, the runner probably shouldn't be 'end'
ing!
Sounds like @weswigham won't have time to work on this, so I can pick it up unless someone beats me to it. |
@weswigham I think v8.2.1 corrected a similar problem... I'm going to give it a shot against typescript. |
And only attach it initially within
start
. Sinceself.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 runs have ended (resulting in an issue akin to #4144).Description of the Change
Essentially, it seems like mocha 8 regressed #4144, but the test added in #4147 didn't seem to catch it, I'm guessing because now the process of of attaching the handlers during
.run
was deferred in some fashion by another change.