From ddf200f34c0dd75f5a1fb5c3bc7144166f0e45a4 Mon Sep 17 00:00:00 2001 From: Miki Date: Wed, 9 Nov 2022 10:19:20 -0800 Subject: [PATCH] Temporarily prevents `task-kill` exceptions on Windows when it is passed a `pid` for a process that is already dead (#2842) Ref: #2811 Signed-off-by: Miki Signed-off-by: Miki Signed-off-by: David Sinclair --- CHANGELOG.md | 1 + packages/osd-opensearch/src/cluster.js | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19cf2d4215a6..5358d5b89b66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Change geckodriver version to make consistency ([#2772](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2772)) - [Multi DataSource] Update default audit log path ([#2793](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2793)) - [Table Visualization] Fix first column sort issue ([#2828](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2828)) +- Temporary workaround for task-kill exceptions on Windows when it is passed a pid for a process that is already dead ([#2842](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2842)) ### 🚞 Infrastructure diff --git a/packages/osd-opensearch/src/cluster.js b/packages/osd-opensearch/src/cluster.js index 7b11b4edbbc5..b4912d677359 100644 --- a/packages/osd-opensearch/src/cluster.js +++ b/packages/osd-opensearch/src/cluster.js @@ -229,7 +229,22 @@ exports.Cluster = class Cluster { throw new Error('OpenSearch has not been started'); } - await treeKillAsync(this._process.pid); + /* Temporary fix for https://github.com/opensearch-project/OpenSearch-Dashboards/issues/2811 + * + * `tree-kill` behaves differently on Windows, where it throws if `pid` is already dead, when + * compared to other operating systems, where it silently returns. + */ + try { + await treeKillAsync(this._process.pid); + } catch (ex) { + console.log('ex.message', ex.message); + if ( + process.platform === 'win32' && + !ex.message?.includes(`The process "${this._process.pid}" not found`) + ) { + throw ex; + } + } await this._outcome; }