Close Lens Proxy on quit of backend (#7453)

- Extract global shared state of shell sessions

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2023-03-31 14:21:31 -04:00
1 parent 2884dea195
commit 908a3cabe1
8 files changed
+99 -31

No files matched your search

@@ -4,13 +4,31 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import { beforeQuitOfBackEndInjectionToken } from "../runnable-tokens/phases";
import { ShellSession } from "../../shell-session/shell-session";
import shellSessionProcessesInjectable from "../../shell-session/processes.injectable";
import prefixedLoggerInjectable from "../../../common/logger/prefixed-logger.injectable";
const cleanUpShellSessionsInjectable = getInjectable({
id: "clean-up-shell-sessions",
instantiate: () => ({
run: () => void ShellSession.cleanup(),
instantiate: (di) => ({
run: () => {
const shellSessionProcesses = di.inject(shellSessionProcessesInjectable);
const logger = di.inject(prefixedLoggerInjectable, "SHELL-SESSIONS");
logger.info("Killing all remaining shell sessions");
for (const { pid } of shellSessionProcesses.values()) {
try {
process.kill(pid);
} catch {
// ignore error
}
}
shellSessionProcesses.clear();
return undefined;
},
}),
injectionToken: beforeQuitOfBackEndInjectionToken,