From 53011f7a9e4b52dbf29a974c9e6b19084ddb59f1 Mon Sep 17 00:00:00 2001 From: liza-mae Date: Mon, 22 Oct 2018 12:10:33 -0600 Subject: [PATCH] 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 --- packages/kbn-es/package.json | 1 + packages/kbn-es/src/cluster.js | 16 +++++++++++++++- packages/kbn-es/yarn.lock | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/kbn-es/package.json b/packages/kbn-es/package.json index 861be267be7fc..9cf983a8e2710 100644 --- a/packages/kbn-es/package.json +++ b/packages/kbn-es/package.json @@ -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" } diff --git a/packages/kbn-es/src/cluster.js b/packages/kbn-es/src/cluster.js index bd744a0e977b0..3767ca0df9c6e 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) { @@ -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}`)); diff --git a/packages/kbn-es/yarn.lock b/packages/kbn-es/yarn.lock index 75cb305b9001f..39336596292d3 100644 --- a/packages/kbn-es/yarn.lock +++ b/packages/kbn-es/yarn.lock @@ -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==