Initial handling of windows process termination (#23441)

* Initial handling of windows process termination

* Update exiting ES cluster process on windows

* Use tree-kill

* Add dependency

* Update with solution from Spencer

* Remove catch statement
This commit is contained in:
liza-mae 2018-10-22 12:10:33 -06:00 committed by GitHub
parent 2d5fe0c123
commit 53011f7a9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View file

@ -16,6 +16,7 @@
"node-fetch": "^2.0.0",
"simple-git": "^1.91.0",
"tar-fs": "^1.16.0",
"tree-kill": "^1.1.0",
"yauzl": "^2.10.0",
"zlib": "^1.0.5"
}

View file

@ -23,6 +23,8 @@ const { installSnapshot, installSource, installArchive } = require('./install');
const { ES_BIN } = require('./paths');
const { log: defaultLog, parseEsLog, extractConfigFiles } = require('./utils');
const { createCliError } = require('./errors');
const { promisify } = require('util');
const treeKillAsync = promisify(require('tree-kill'));
exports.Cluster = class Cluster {
constructor(log = defaultLog) {
@ -135,17 +137,25 @@ exports.Cluster = class Cluster {
await this._outcome;
}
_stopCalled = false;
/**
* Stops ES process, if it's running
*
* @returns {Promise}
*/
async stop() {
if (this._stopCalled) {
return;
}
this._stopCalled = true;
if (!this._process || !this._outcome) {
throw new Error('ES has not been started');
}
this._process.kill();
await treeKillAsync(this._process.pid);
await this._outcome;
}
@ -190,6 +200,10 @@ exports.Cluster = class Cluster {
this._outcome = new Promise((resolve, reject) => {
this._process.once('exit', code => {
if (this._stopCalled) {
resolve();
return;
}
// JVM exits with 143 on SIGTERM and 130 on SIGINT, dont' treat them as errors
if (code > 0 && !(code === 143 || code === 130)) {
reject(createCliError(`ES exited with code ${code}`));

View file

@ -373,7 +373,7 @@ tar-stream@^1.1.2:
readable-stream "^2.0.0"
xtend "^4.0.0"
tree-kill@^1.2.0:
tree-kill@^1.1.0, tree-kill@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.0.tgz#5846786237b4239014f05db156b643212d4c6f36"
integrity sha512-DlX6dR0lOIRDFxI0mjL9IYg6OTncLm/Zt+JiBhE5OlFcAR8yc9S7FFXU9so0oda47frdM/JFsk7UjNt9vscKcg==