Skip to content

Commit

Permalink
fix leaking uncaughtException handler
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Jan 9, 2020
1 parent 69339a3 commit 71ce33c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/runner.js
Expand Up @@ -908,9 +908,15 @@ Runner.prototype.run = function(fn) {

fn = fn || function() {};

// uncaught exception within runner
function uncaught(err) {
self.uncaught(err);
}
// uncaught exception after runner's end event
function uncaughtEnd(err) {
if (err instanceof Pending) return;
throw err;
}

function start() {
// If there is an `only` filter
Expand Down Expand Up @@ -940,17 +946,16 @@ Runner.prototype.run = function(fn) {
this.on(constants.EVENT_RUN_END, function() {
debug(constants.EVENT_RUN_END);
process.removeListener('uncaughtException', uncaught);
process.on('uncaughtException', function(err) {
if (err instanceof Pending) {
return;
}
throw err;
});
process.on('uncaughtException', uncaughtEnd);
// console.log(process.listeners('uncaughtException'));
fn(self.failures);
});

// uncaught exception
// process.removeListener('uncaughtException', uncaughtEnd); ?? does not work
process.removeAllListeners('uncaughtException');
process.on('uncaughtException', uncaught);
// console.log(process.listeners('uncaughtException')[0]);

if (this._delay) {
// for reporters, I guess.
Expand Down

0 comments on commit 71ce33c

Please sign in to comment.