fix(Launcher): force-kill chrome on process exit and interruption (#1155)

This patch starts force-killing chromium regardless of custom userdata
directory when the node process exits.

References #1047
This commit is contained in:
Andrey Lushnikov 2017-10-24 16:05:12 -07:00 committed by GitHub
parent b9ab6fe4bb
commit ab9b34cd5d

View File

@ -125,9 +125,9 @@ class Launcher {
}); });
}); });
const listeners = [ helper.addEventListener(process, 'exit', killChrome) ]; const listeners = [ helper.addEventListener(process, 'exit', forceKillChrome) ];
if (options.handleSIGINT !== false) if (options.handleSIGINT !== false)
listeners.push(helper.addEventListener(process, 'SIGINT', killChrome)); listeners.push(helper.addEventListener(process, 'SIGINT', forceKillChrome));
/** @type {?Connection} */ /** @type {?Connection} */
let connection = null; let connection = null;
try { try {
@ -146,6 +146,16 @@ class Launcher {
function killChrome() { function killChrome() {
helper.removeEventListeners(listeners); helper.removeEventListeners(listeners);
if (temporaryUserDataDir) { if (temporaryUserDataDir) {
forceKillChrome();
} else if (connection) {
// Attempt to close chrome gracefully
connection.send('Browser.close');
}
return waitForChromeToClose;
}
function forceKillChrome() {
helper.removeEventListeners(listeners);
if (chromeProcess.pid && !chromeProcess.killed && !chromeClosed) { if (chromeProcess.pid && !chromeProcess.killed && !chromeClosed) {
// Force kill chrome. // Force kill chrome.
if (process.platform === 'win32') if (process.platform === 'win32')
@ -157,11 +167,6 @@ class Launcher {
try { try {
removeFolder.sync(temporaryUserDataDir); removeFolder.sync(temporaryUserDataDir);
} catch (e) { } } catch (e) { }
} else if (connection) {
// Attempt to close chrome gracefully
connection.send('Browser.close');
}
return waitForChromeToClose;
} }
} }