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)
listeners.push(helper.addEventListener(process, 'SIGINT', killChrome));
listeners.push(helper.addEventListener(process, 'SIGINT', forceKillChrome));
/** @type {?Connection} */
let connection = null;
try {
@ -146,23 +146,28 @@ class Launcher {
function killChrome() {
helper.removeEventListeners(listeners);
if (temporaryUserDataDir) {
if (chromeProcess.pid && !chromeProcess.killed && !chromeClosed) {
// Force kill chrome.
if (process.platform === 'win32')
childProcess.execSync(`taskkill /pid ${chromeProcess.pid} /T /F`);
else
process.kill(-chromeProcess.pid, 'SIGKILL');
}
// Attempt to remove temporary profile directory to avoid littering.
try {
removeFolder.sync(temporaryUserDataDir);
} catch (e) { }
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) {
// Force kill chrome.
if (process.platform === 'win32')
childProcess.execSync(`taskkill /pid ${chromeProcess.pid} /T /F`);
else
process.kill(-chromeProcess.pid, 'SIGKILL');
}
// Attempt to remove temporary profile directory to avoid littering.
try {
removeFolder.sync(temporaryUserDataDir);
} catch (e) { }
}
}
/**