Skip to content

Commit

Permalink
Initial handling of windows process termination (#23441)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
liza-mae authored Oct 22, 2018
1 parent 2d5fe0c commit 53011f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/kbn-es/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
16 changes: 15 additions & 1 deletion packages/kbn-es/src/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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}`));
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit 53011f7

Please sign in to comment.