feat: Use tree-kill module to kill sessions on Windows
This commit is contained in:
1 parent
fefae2b73d
commit
c5b0061428
3 files changed
+19
-3
No files matched your search
@@ -28,7 +28,8 @@
|
||||
"lookpath": "^1.1.0",
|
||||
"node-html-parser": "^3.1.3",
|
||||
"semver": "^7.3.5",
|
||||
"shell-quote": "^1.7.2"
|
||||
"shell-quote": "^1.7.2",
|
||||
"tree-kill": "^1.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@electron-forge/cli": "6.0.0-beta.54",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
const { spawnAsyncJSONPromise } = require('../helpers/spawn-promise.js');
|
||||
const treeKill = require('tree-kill');
|
||||
const sanitizer = require('../utils/sanitizer.js');
|
||||
const { isWindows } = require('../helpers/platform.js');
|
||||
const { spawnAsyncJSONPromise } = require('../helpers/spawn-promise.js');
|
||||
|
||||
class Session {
|
||||
#id;
|
||||
@@ -60,10 +62,18 @@ class Session {
|
||||
*/
|
||||
stop() {
|
||||
return new Promise((resolve, reject) => {
|
||||
debugger;
|
||||
if (this.isRunning) {
|
||||
this.#process.on('close', () => resolve());
|
||||
this.#process.on('error', (e) => reject(e));
|
||||
this.#process.kill();
|
||||
/**
|
||||
* On Windows OS, a spawned process uses cmd.exe to initiate a session.
|
||||
* Hence, captured process.pid corresponds to cmd.exe instead of session.
|
||||
* To avoid orphaned session processes and due to lack of node support
|
||||
* to handle killing processes cleanly in this scenario,
|
||||
* kill entire dependent process tree on Windows.
|
||||
*/
|
||||
isWindows() ? treeKill(this.#process.pid) : this.#process.kill();
|
||||
} else {
|
||||
// Do nothing when process isn't running
|
||||
resolve();
|
||||
|
||||
@@ -3590,6 +3590,11 @@ tough-cookie@~2.5.0:
|
||||
psl "^1.1.28"
|
||||
punycode "^2.1.1"
|
||||
|
||||
tree-kill@^1.2.2:
|
||||
version "1.2.2"
|
||||
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
|
||||
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==
|
||||
|
||||
trim-newlines@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613"
|
||||
|
||||
Reference in new issue
Block a user