From 5c9fd389a96c6e38dbc9fd3244298b258a12bbc7 Mon Sep 17 00:00:00 2001 From: Lauri Nevala Date: Mon, 8 Jun 2020 12:05:45 +0300 Subject: [PATCH] Kill shell process by pid Signed-off-by: Lauri Nevala --- src/main/shell-session.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/shell-session.ts b/src/main/shell-session.ts index bc2235ad36..97f3b19701 100644 --- a/src/main/shell-session.ts +++ b/src/main/shell-session.ts @@ -8,6 +8,7 @@ import { Kubectl } from "./kubectl" import { tracker } from "./tracker" import { Cluster, ClusterPreferences } from "./cluster" import { helmCli } from "./helm-cli" +import logger from "./logger" export class ShellSession extends EventEmitter { static shellEnv: any @@ -159,12 +160,14 @@ export class ShellSession extends EventEmitter { } protected exit(code = 1000) { - this.websocket.close(code) + logger.debug("Shell closed") + if (this.websocket.readyState == this.websocket.OPEN) this.websocket.close(code) this.emit('exit') } protected closeWebsocketOnProcessExit() { this.shellProcess.on("exit", (code) => { + logger.debug("Shell process exited", code) this.running = false let timeout = 0 if (code > 0) { @@ -180,7 +183,13 @@ export class ShellSession extends EventEmitter { protected exitProcessOnWebsocketClose() { this.websocket.on("close", () => { if (this.shellProcess) { - this.shellProcess.kill(); + logger.debug("Killing shell process") + try { + process.kill(this.shellProcess.pid) + } catch(e) { + logger.debug("Process id not exist") + } + this.emit('exit') } }) }