From c9b0a6c060063965ac4f4b6ea18210632a14928a Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 29 Aug 2017 22:49:50 -0700 Subject: [PATCH] Fix launcher to not leak event listeners (#605) This patch fixes launcher to not leak event listeners. --- lib/Launcher.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/Launcher.js b/lib/Launcher.js index feac7173c81..c78e025b725 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -85,13 +85,12 @@ class Launcher { } // Cleanup as processes exit. - let killed = false; - process.once('exit', killChrome); if (temporaryUserDataDir) chromeProcess.once('close', () => removeSync(temporaryUserDataDir)); + const listeners = [ helper.addEventListener(process, 'exit', killChrome) ]; if (options.handleSIGINT !== false) - process.once('SIGINT', killChrome); + listeners.push(helper.addEventListener(process, 'SIGINT', killChrome)); try { const connectionDelay = options.slowMo || 0; @@ -104,9 +103,7 @@ class Launcher { } function killChrome() { - if (killed) - return; - killed = true; + helper.removeEventListeners(listeners); if (process.platform === 'win32') childProcess.execSync(`taskkill /pid ${chromeProcess.pid} /T /F`); else