diff --git a/packages/kbn-es/package.json b/packages/kbn-es/package.json index fedd51bbee442..116630eac946f 100644 --- a/packages/kbn-es/package.json +++ b/packages/kbn-es/package.json @@ -17,6 +17,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" } diff --git a/packages/kbn-es/src/cluster.js b/packages/kbn-es/src/cluster.js index bd744a0e977b0..f14be3582f71a 100644 --- a/packages/kbn-es/src/cluster.js +++ b/packages/kbn-es/src/cluster.js @@ -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) { @@ -141,11 +143,17 @@ exports.Cluster = class Cluster { * @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 +198,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}`)); diff --git a/packages/kbn-es/yarn.lock b/packages/kbn-es/yarn.lock index 011c1f888054c..b96d9512b1014 100644 --- a/packages/kbn-es/yarn.lock +++ b/packages/kbn-es/yarn.lock @@ -483,7 +483,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==