From b2816287c9cd6bd4bd8be77d5dd7dc1b38eaf752 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 10 Jun 2020 14:16:14 -0700 Subject: [PATCH] Move removal of `uncaughtException` handler into `end` callback 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 #4144). --- lib/runner.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/runner.js b/lib/runner.js index 22e7bb91d6..6851ab281b 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -989,6 +989,7 @@ Runner.prototype.run = function(fn, opts) { fn = fn || function() {}; function start() { + self._addEventListener(process, 'uncaughtException', self.uncaught); debug('run(): starting'); // If there is an `only` filter if (rootSuite.hasOnly()) { @@ -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); }); - self._removeEventListener(process, 'uncaughtException', self.uncaught); - self._addEventListener(process, 'uncaughtException', self.uncaught); - if (this._delay) { // for reporters, I guess. // might be nice to debounce some dots while we wait.